290 likes | 675 Vues
ITI-481: Unix Administration Meeting 5 Christopher Uriarte Rutgers University Center for Applied Computing Technologies Today’s Agenda Job Scheduling - The Cron Program Syslogd and Logging Sendmail and UNIX mail concepts The Cron Program UNIX’s answer to automated job scheduling.
E N D
ITI-481: Unix AdministrationMeeting 5Christopher UriarteRutgers University Center for Applied Computing Technologies
Today’s Agenda • Job Scheduling - The Cron Program • Syslogd and Logging • Sendmail and UNIX mail concepts
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.
Cron Files • Configuration files defining scheduled jobs are generally stored in the directory: /var/spool/cronThe main Cron directory, where jobs defined according to username. These definition files are called crontab files.
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.
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”
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.
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
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)
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)
/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.
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.
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.
/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`
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.
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.
Sample Exchange: Sending, Receiving and Retrieving Electronic Mail Sending Mail Receiving Mail Retrieving Mail Mail Spool MDA SMTP Connection SMTP Server SMTP Server POP Server MTA MTA SMTP and POP Servers can be the same system POP Connection SMTP Relay MUA MUA Workstation Workstation
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.
Sample SMTP Exchange with a Mail Server amenti 5.5 [~] > telnet internet.rutgers.edu 25 Trying 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 -0400 helo foobar.com 250 iti.rutgers.edu Hello amenti.rutgers.edu [165.230.116.133], pleased to meet you mail from: kkaplan@foobar.com 250 kkaplan@foobar.com... Sender ok rcpt to: kkaplan@rci.rutgers.edu 551 we do not relay rcpt to: kkaplan@internet.rutgers.edu 250 kkaplan@internet.rutgers.edu... Recipient ok data 354 Enter mail, end with "." on a line by itself This is a test. . 250 UAA03425 Message accepted for delivery
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: foo@foobar.com <enter>rcpt to: youritiname@iti.rutgers.edu <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?
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.
Sendmail Components • /usr/sbin/sendmailSendmail binary. Started by default with options –bd –q1h. Sendmail is started by an rc script when system boots. • /etc/sendmail.cfMain 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/aliasesUsed to create mailing lists or to give users alternative email address. • /var/spool/mqueueQueue for outgoing email messages.
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.
Aliases File • Entry format:username: newusergroupname: user1, user2 • Sample enties:root: kkaplan@internet.rutgers.edustaff: kkaplan,jsmith,jdoe • After editing /etc/aliases, for changes to take effect, need to run:> /usr/bin/newaliases
Exercise: Creating Aliases • Add the following entries to /etc/aliases:root: student, youremail@domain.com • Type:> /usr/bin/newaliases • Verify that your aliases are working:> echo “checking aliases” |/bin/mail root> cat /var/spool/mail/student
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.
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
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.
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.