introduction to unix – cs 21 lecture 18. lecture overview running programs at certain times linux...

40
Introduction to Unix – CS 21 Lecture 18

Upload: bartholomew-nicholson

Post on 31-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Introduction to Unix – CS 21

Lecture 18

Page 2: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Lecture Overview Running programs at certain times Linux Distributions Installing packages

Standard ways of distribution packages Configure scripts apt-get Rpm

Connecting to other machines and X-windows

Quiz #3

Page 3: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Running Processes At Certain Times What are your options if you want

to run a program once every day? Manually run it once every day

Sometimes it’s a hassle and you forget Write a script that you run that

performs a task once a day Script could be killed or the system could

be rebooted Utilize cron to run your program

Page 4: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Why Would You Want To Do This? Run backups

At least once a night if not more often Checking for updates

Write your own version of automatic update Keep statistics

Calculate the average number of people logged on per hour

Reminders If you are working too hard and forget about

some important event

Page 5: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

The cron Daemon crond

Always running in the background Starts up every time a Unix machine

boots up Once a minute, checks certain files to

see if anything needs to be run

Page 6: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

How crond Works

User’s cron Table

crondDo I run anything now?

1 Minute!Wake up!

Back to sleep

Page 7: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

A Daemon Program Not some supernatural creature that

lives in your computer A program that is run in the background

from the very beginning Typically has no input or output except

to log files Constantly checks and handles some

events in the background Examples: printer daemons, network

connection daemons

Page 8: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

The crontab Program Usage: crontab file

Replace your current cron table with the one located in “file”

Alternate usage: crontab [OPTION] -l

Show your current cron table -r

Remove your current cron table -e

Edit your current cron table

Page 9: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Steps For Using crontab Edit a file with a list of times and

commands Run “crontab file” Wait…

Any errors when running commands will be automatically mailed to you

Page 10: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Fields Of A crontab File Minute: 0-59 Hour: 0-23 (military time) Day of the month: 1-31 Month: 1-12 (or names) Day of the week: 0-7 (0 and 7 are

Sunday) Each item can be an individual

item, a hyphenated list, or a *

Page 11: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Example

Page 12: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Getting Your Own Unix System By now, you have been introduced

to a lot of the workings of Unix How do you go about getting a

working version? Several free options available for

download Linux BSD

Page 13: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Different Distributions Of Linux Redhat

Selling support Sponsors Fedora

Mandrake Ease of use

Debian The do-it-yourself version

Gentoo Slackware

Page 14: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Distribution Differences The kernel (actual operating system)

is the same with each distribution Differences are again in the bells

and whistles All of the user and graphical interfaces

look different Different sets of programs available

from the start with different distributions

Page 15: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Installing Packages When using Linux, you will

undoubtedly run into programs that are updated frequently or may not be available on your installation www.gnu.org freshmeat.net

A couple of standard package distribution forms exist

Page 16: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Installing Packages From tarballs The most common way programs

are distributed: package.tar.gz Usually include the source code

May include only the executables Unfortunately, no standard exists

for tarball distributions Pseudo-standard exists, but you

should always read the documentation

Page 17: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

“Standard” Installation Procedure Step 1: tar -xzvf Step 2: configure Step 3: make Step 4 (optional): make install

Page 18: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Configure Scripts Each package comes with its own

script called “configure” Designers write these as checks to

see what tools are available on each and create a particular Makefile according to what was detected

Page 19: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Example

Page 20: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Once configure Has Run Running “make” should create

executables Running “make install” places

those executables in common locations /bin or /usr/local/bin Must have permission (should be

root)

Page 21: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Problems Sometimes, configure scripts don’t always

run correctly Some necessary tool is missing on your system Worse, you know you have the tool but

configure can’t find it! Getting something installed can turn into a

long, ugly process Keep in mind, there is no magic here

Configure scripts are simply shell programs just like the kind you have written, although longer

Page 22: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Other Package Distributions rpm

Redhat package manager (Also used by Mandrake)

apt-get Used in Debian systems (Fedora Core 2 has support as well)

Page 23: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

RPM Both a file format and a program

packages.rpm rpm –i package.rpm

Usage: rpm [OPTION] packageFile -i, -u, -f

Install, update, or freshen -e

Erase -q

Query

Page 24: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

apt-get Debian systems

Fedora Core uses them too Package Manager

Automatically retrieves (over an internet connection) and installs packages that you specify

Page 25: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Using Unix In A Networked Environment Unix has powerful networking

features built in Sockets and ports are easily accessible

For all the gory details about setting up your Unix machine, take cs183 In the meantime, check out netconfig

and ifconfig Must be root to run these

Page 26: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

rlogin, telnet, ftp rlogin and telnet

Remote login Used to open up terminals on other systems

ftp File transfer protocol Used to transfer files efficiently

All unsafe as everything is sent in plain text Anyone watching can see what your password

is and break in

Page 27: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

ssh – The Secure Alternative To telnet And rlogin Secure shell

Opens a terminal on another system just like telnet and rlogin

Sends all information (not just password) encrypted

Slight Problem: ssh1 and ssh2 are incompatible Not as much a problem nowadays as it used

to be

Page 28: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Scp – The Secure Alternative To ftp Secure copy

Works just like cp, only the source or destination can be a different machine

Usage: scp source destination Example:

scp myFile [email protected]:myFile

Copies myFile to eon

Page 29: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

If ftp Isn’t Safe, Why Does Everyone Use It? Many, many web pages have ftp links Most of the package distributions are

done over ftp Most ftp sites allow anonymous logins

Login name: anonymous Password: email address (or anything) Anonymous logins and open source

software isn’t worth stealing

Page 30: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

The GUI Of Unix: X-Windows Some systems you will encounter (or set

up like Debian) default to the command line interface

Everything we’ve done so far in this class has primarily been command line driven

In an effort to be more appealing and user friendly, a standard for graphical user interfaces was created - X

Page 31: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Working With X-Windows startx or x in order to run X windows The version everyone uses is Version

11, Revision 6 X11R6

Initialization files .xinitrc .xsession Used to start xterms

Terminals on top of the X-windows environment

Page 32: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

GUI Components

Window Manager

Window System

Kernel

User

Page 33: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

What Does Each Part Do? Windows System

Controls basic functionality like resizing windows and creating windows

Windows Manager Controls how these functionalities

appear Example: a slider or button will resize a

window

Page 34: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Windows Managers Just like different distributions, different

window managers exist KDE Gnome FVWM2

All try to create their own look and feel Some have more features than others,

but I can’t say one is better than any other

Page 35: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

KDE Example

Page 36: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Controlling Access xhost

Allows or disallows other machines to open up windows on your display

Usage: xhost +machineName Other Usage: xhost –machineName

The DISPLAY variable Tells the system where to send windows

(where X connections go) export DISPLAY=283-13.cs.ucr.edu:0.0

Page 37: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Why Would You Ever Do That? If you open up a window on

someone else’s machine, you don’t have control over it!

If you want two people to work on modifying a file at the same time, you can open up an emacs window on another machine

Page 38: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

A Unix Environment In Windows X-Win32

Simply allows X connections from another machine to be displayed on your Windows machine

Not free, however Cygwin

A sort of emulation of Linux running as a Windows process

Freely available

Page 39: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Next Time Review of class

Bring any questions you would like discussed

Study guide Should be posted later today A list of many, many questions like

those that will appear on the final

Page 40: Introduction to Unix – CS 21 Lecture 18. Lecture Overview Running programs at certain times Linux Distributions Installing packages Standard ways of distribution

Quiz #3 Good Luck