29
ITI-481: Unix Administration Meeting 5 Christopher Uriarte Rutgers University Center for Applied Computing Technologies

Unix Administration 5

Embed Size (px)

DESCRIPTION

http://www.cju.com/classes/2002/ITI481-03/

Citation preview

Page 1: Unix Administration 5

ITI-481: Unix AdministrationMeeting 5

Christopher UriarteRutgers University

Center for Applied Computing Technologies

Page 2: Unix Administration 5

Today’s Agenda

• Job Scheduling - The Cron Program

• Syslogd and Logging

• Sendmail and UNIX mail concepts

Page 3: Unix Administration 5

The Cron Program

• UNIX’s answer to automated job scheduling.• Used to schedule jobs to run at particular time

or at a particular frequency.• Useful to to automate system administration

tasks.• Powered by a background system process

called crond (the cron daemon) is started at boot time from rc scripts.

Page 4: Unix Administration 5

Cron Files

• Configuration files defining scheduled jobs are generally stored in the directory:/var/spool/cron

The main Cron directory, where jobs defined according to username. These definition files are called crontab files.

Page 5: Unix Administration 5

Cron Files, con’t.

• Each user on the system can have a corresponding crontab file specifying their own automated job schedule – including root.

• The simple text files are kept under the /var/spool/cron directory, named after each user, e.g.:– /var/spool/cron/root– /var/spool/cron/chris– /var/spool/cron/mary– etc.

Page 6: Unix Administration 5

Crontab File Format• Crontab files use the following format, placing one job entry

on each line:Minute Hour Day Month DayOfWeek Command

• Time fields are as follows:– Minute (0-59)– Hour (0-23)– Day of Month (1-31)– Month (1-12 or names jan-dec– Day of Week (0-6 or names mon-fri)– Command: A command, script or program name to run at the time specified

• Fields that are not specified for a particular entry are substituted with “*”

• Ranges can be specified by placing a “-” between elements, such as “mon-fri”

Page 7: Unix Administration 5

Crontab File Formatting Rules

• Fields that are not specified for a particular entry are substituted with “*”– As you definitions for more fields, the execution time

generally becomes more specific.

• Ranges of dates or times can be specified by placing a “-” between elements, such as “mon-fri” or “1-5”

• Multiple dates or times for a field can be specified by specified using a comma between values, such as “mon,wed,fri”, which will execute a job on Monday, Wednesday and Friday.

Page 8: Unix Administration 5

Sample Cron Entries

• Sample entries:#Ping our mail file server’s IP address every 15 min0,15,30,45**** /sbin/ping –5 192.168.15.7 | /bin/mail root

#Mail a disk usage report every Friday at 5:00PM0 17 * * fri df |/bin/mail root

Remember the format!:

Minute Hour Day Month DayOfWeek Command

Page 9: Unix Administration 5

Editing Crontab files• Although crontab files are simple text files, they

cannot be edited by opening them directly with a text editor like vi,emacs,pico, etc.

• You must use the crontab program to edit a user’s crontab file:

• To use the crontab:> crontab –u username –e

• Crontab will open the specified crontab file in the default system editor (usually vi). You can have it use your favorite text editor by setting the EDITOR environment varialble (I.e. EDITOR=pico)

Page 10: Unix Administration 5

Editing Crontab files, con’t.

• When you have completed editing your crontab file, exit your text editor as your normally would. Be sure to save the file you’ve just created (the crontab program will give the file a default name and location)

• If you do not format your cron entry correctly, the cron program will notify you when you attempt to exit your editor.

• You will then have the chance to fix the entry or exit your editor (which leaves the crontab file unmodified)

Page 11: Unix Administration 5

/etc/crontab

• Defines a set of directories that will run scripts or links located in those directories at specified times.

• Predefined cron directories:/etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly

• Non-standard way of using cron.

Page 12: Unix Administration 5

Exercise: Creating Crontab Entries

• Edit the root crontab file:> cd /var/spool/cron> crontab –u root -e

• Create a crontab entry to run out of the root account to email a disk usage report to your internet.rutgers.edu account or another email address of your choice every 15 minutes of the hour.

• Check /var/log/cron to verify that your job ran.

Page 13: Unix Administration 5

Syslogd

• Most system logging is handled through the syslogd.• Configuration file is /etc/sylog.conf.• Log entries are directed to various files in /var/log.• Messages logged by syslogd include a time stamp,

the process or facility that delivered the message, and the message itself.

• Rotating log files periodically is recommended.

Page 14: Unix Administration 5

/etc/syslog.conf

• Format of syslog rule:facility.priority action– facility - system or application generating the message.– priority – level of severity of the message.– Wild cards are accepted.

• Sample entries:authpriv.* /var/log/securemail.err /var/log/maillog

• Tab delineated file.• If changes are made need to restart syslog daemon:> kill –HUP `cat /var/run/syslog.pid`

Page 15: Unix Administration 5

Additional Log Files

• /var/run/utmp – information about who is currently logged into system. Used by commands such as who and finger.

• /var/log/wtmp – login times and duration for each user on the system. Can view with last command.

• /var/log/lastlog – similar to wtmp but used by different programs, such as finger.

Page 16: Unix Administration 5

Electronic Mail System Components

• Mail User Agent (MUA)– Provides interface for reading mail, writing new messages, and

filing. Also called a mailer. – Examples: mail, Pine, Netscape Mail, Outlook.

• Mail Transport Agent(MTA)– Routes mail from one user to another either locally or across

systems.– Uses a transport protocol, usually SMTP (Simple Mail Transport

Protocol), to provide the medium for mail transfer.– Examples: Sendmail, Qmail.

• Mail Delivery Agent (MDA)– Takes a message once received at a site and gets it to the

appropriate user mailbox.– Examples: procmail, mail.

Page 17: Unix Administration 5

Workstation Workstation

POP ServerSMTP Server

Mail Spool

SMTP Server

SMTP and POP Servers can be the same system

Sending Mail Retrieving Mail

SMTP Relay

SMTP Connection

POP Connection

Receiving Mail

MUA

MTA MTA

MDA

MUA

Sample Exchange: Sending, Receiving and Retrieving Electronic Mail

Page 18: Unix Administration 5

SMTP

• The SMTP protocol defines the method by which mail is sent from one host to another.

• SMTP usually uses port 25 – mail servers will be “listening” for incoming mail messages.

• No authentication required to use SMTP services – anybody can send mail without providing a username/password to send it.

Page 19: Unix Administration 5

Sample SMTP Exchange with a Mail Serveramenti 5.5 [~] > telnet internet.rutgers.edu 25Trying 165.230.30.68...Connected to iti.Rutgers.EDU.Escape character is '^]'.220 iti.rutgers.edu ESMTP Sendmail 8.9.3/8.8.7; Mon, 15 May 2000 20:32:48 -

0400helo foobar.com250 iti.rutgers.edu Hello amenti.rutgers.edu [165.230.116.133], pleased to

meet youmail from: [email protected] [email protected]... Sender okrcpt to: [email protected] we do not relayrcpt to: [email protected] [email protected]... Recipient okdata354 Enter mail, end with "." on a line by itselfThis is a test..250 UAA03425 Message accepted for delivery

Page 20: Unix Administration 5

Exercise: Sending a Message• Log into iti.rutgers.edu using ssh.• Telnet to port 25 on your iti.rutgers.edu:

> telnet iti.rutgers.edu 25• Compose and send out an email message:

helo foobar.com <enter>mail from: [email protected] <enter>rcpt to: [email protected] <enter> data <enter>This is a test. <enter>. <enter><control> ]

• Verify that your message was received:> less /var/spool/mail/youritiname

• Try reading the message in pine. type:> pineAccess your inbox. What information about the message is hidden from the typical user view?

Page 21: Unix Administration 5

Sendmail

• Can be downloaded from http://www.sendmail.org.

• Started from /etc/rc.d/init.d/sendmail at boot time.

• Responsible for sending and receiving email messages. Once mail is received, it gets passed off to a MDA to deliver message to appropriate user mail box.

Page 22: Unix Administration 5

Sendmail Components• /usr/sbin/sendmail

Sendmail binary. Started by default with options –bd –q1h. Sendmail is started by an rc script when system boots.

• /etc/sendmail.cf Main configuration file. Defines rule sets that dictate Sendmail's behavior. Often also points to other sendmail configuration files in /etc.

• /etc/aliases or /etc/mail/aliases Used to create mailing lists or to give users alternative email address.

• /var/spool/mqueue Queue for outgoing email messages.

Page 23: Unix Administration 5

Receiving Electronic Mail

• The default storage location for incoming mail is /var/spool/mail/username.

• Mail can be redirected to other local or remote email address through .forward files in user home directories or /etc/aliases on a system level.

Page 24: Unix Administration 5

Aliases File

• Entry format:username: newusergroupname: user1, user2

• Sample enties:root: [email protected]: kkaplan,jsmith,jdoe

• After editing /etc/aliases, for changes to take effect, need to run:> /usr/bin/newaliases

Page 25: Unix Administration 5

Exercise: Creating Aliases

• Add the following entries to /etc/aliases:root: student, [email protected]

• Type:> /usr/bin/newaliases

• Verify that your aliases are working:> echo “checking aliases” |/bin/mail root> cat /var/spool/mail/student

Page 26: Unix Administration 5

Retrieving and Reading Email

• SMTP is a transport mechanism for sending mail only. An SMTP server will not allow a user to read or retrieve his/her mail.

• Options for reading or retrieving email:– Use a MUA to access directly the file system where the

incoming mail is stored.– Post Office Protocol (POP) – permits mail to be

downloading from a POP server to a POP client.– Internet Message Access Protocol (IMAP) – IMAP

server maintains a central repository for IMAP account mail messages. Users can read, write, and file messages using an IMAP client.

Page 27: Unix Administration 5

POP3

• Uses a server process to handle requests to retrieve email.

• Usually uses port 110.• Unlike SMTP, POP is an authenticated

protocol. (users must provide a username and password to retrieve mail)

• Installed by default and enabled on most UNIX systems

Page 28: Unix Administration 5

IMAP

• Very similar to POP – however, not yet as popular.

• Uses a server process to handle requests to retrieve email.

• Usually uses port 143.• IMAP is an authenticated protocol. (users

must provide a username and password to retrieve mail)

• Installed by default and enabled on most UNIX systems.

Page 29: Unix Administration 5

Job Scheduling in UNIX• Sometimes its desirable to schedule an application

or script to execute unattended at a certain time of day or at a certain frequency.– System backups (backup the /home filesystem to tape every night

at 2:00am)– Scripts that check system files (check to see if the /etc/password

and and /etc/shadow files have been changed in the last 24 hours and email me if they have)

– Scripts that mail reports or log files (email me the last 200 lines of the system security log every morning)

• UNIX administrators need a reliable way to schedule unattended jobs and, possibly, give users the ability to schedule unattended jobs.