Unix Administration 5


Published on


Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Unix Administration 5

  1. 1. ITI-481: Unix Administration Meeting 5 Christopher Uriarte Rutgers University Center for Applied Computing Technologies
  2. 2. Today’s Agenda <ul><li>Job Scheduling - The Cron Program </li></ul><ul><li>Syslogd and Logging </li></ul><ul><li>Sendmail and UNIX mail concepts </li></ul>
  3. 3. The Cron Program <ul><li>UNIX’s answer to automated job scheduling. </li></ul><ul><li>Used to schedule jobs to run at particular time or at a particular frequency. </li></ul><ul><li>Useful to to automate system administration tasks. </li></ul><ul><li>Powered by a background system process called crond (the cron daemon) is started at boot time from rc scripts. </li></ul>
  4. 4. Cron Files <ul><li>Configuration files defining scheduled jobs are generally stored in the directory: </li></ul><ul><ul><li>/var/spool/cron The main Cron directory, where jobs defined according to username. These definition files are called crontab files . </li></ul></ul>
  5. 5. Cron Files, con’t. <ul><li>Each user on the system can have a corresponding crontab file specifying their own automated job schedule – including root. </li></ul><ul><li>The simple text files are kept under the /var/spool/cron directory, named after each user, e.g.: </li></ul><ul><ul><li>/var/spool/cron/root </li></ul></ul><ul><ul><li>/var/spool/cron/chris </li></ul></ul><ul><ul><li>/var/spool/cron/mary </li></ul></ul><ul><ul><li>etc. </li></ul></ul>
  6. 6. Crontab File Format <ul><li>Crontab files use the following format, placing one job entry on each line: Minute Hour Day Month DayOfWeek Command </li></ul><ul><li>Time fields are as follows: </li></ul><ul><ul><li>Minute (0-59) </li></ul></ul><ul><ul><li>Hour (0-23) </li></ul></ul><ul><ul><li>Day of Month (1-31) </li></ul></ul><ul><ul><li>Month (1-12 or names jan-dec </li></ul></ul><ul><ul><li>Day of Week (0-6 or names mon-fri) </li></ul></ul><ul><ul><li>Command: A command, script or program name to run at the time specified </li></ul></ul><ul><li>Fields that are not specified for a particular entry are substituted with “*” </li></ul><ul><li>Ranges can be specified by placing a “-” between elements, such as “mon-fri” </li></ul>
  7. 7. Crontab File Formatting Rules <ul><li>Fields that are not specified for a particular entry are substituted with “*” </li></ul><ul><ul><li>As you definitions for more fields, the execution time generally becomes more specific. </li></ul></ul><ul><li>Ranges of dates or times can be specified by placing a “-” between elements, such as “mon-fri” or “1-5” </li></ul><ul><li>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. </li></ul>
  8. 8. Sample Cron Entries <ul><li>Sample entries: #Ping our mail file server’s IP address every 15 min 0,15,30,45**** /sbin/ping –5 | /bin/mail root </li></ul><ul><li>#Mail a disk usage report every Friday at 5:00PM 0 17 * * fri df |/bin/mail root </li></ul><ul><li>Remember the format!: </li></ul><ul><li>Minute Hour Day Month DayOfWeek Command </li></ul>
  9. 9. Editing Crontab files <ul><li>Although crontab files are simple text files, they cannot be edited by opening them directly with a text editor like vi,emacs,pico, etc. </li></ul><ul><li>You must use the crontab program to edit a user’s crontab file: </li></ul><ul><li>To use the crontab: > crontab –u username –e </li></ul><ul><li>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) </li></ul>
  10. 10. Editing Crontab files, con’t. <ul><li>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) </li></ul><ul><li>If you do not format your cron entry correctly, the cron program will notify you when you attempt to exit your editor. </li></ul><ul><li>You will then have the chance to fix the entry or exit your editor (which leaves the crontab file unmodified) </li></ul>
  11. 11. /etc/crontab <ul><li>Defines a set of directories that will run scripts or links located in those directories at specified times. </li></ul><ul><li>Predefined cron directories: /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly </li></ul><ul><li>Non-standard way of using cron. </li></ul>
  12. 12. Exercise: Creating Crontab Entries <ul><li>Edit the root crontab file: > cd /var/spool/cron > crontab –u root -e </li></ul><ul><li>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. </li></ul><ul><li>Check /var/log/cron to verify that your job ran. </li></ul>
  13. 13. Syslogd <ul><li>Most system logging is handled through the syslogd. </li></ul><ul><li>Configuration file is /etc/sylog.conf . </li></ul><ul><li>Log entries are directed to various files in /var/log . </li></ul><ul><li>Messages logged by syslogd include a time stamp, the process or facility that delivered the message, and the message itself. </li></ul><ul><li>Rotating log files periodically is recommended. </li></ul>
  14. 14. /etc/syslog.conf <ul><li>Format of syslog rule: facility.priority action </li></ul><ul><ul><li>facility - system or application generating the message. </li></ul></ul><ul><ul><li>priority – level of severity of the message. </li></ul></ul><ul><ul><li>Wild cards are accepted. </li></ul></ul><ul><li>Sample entries: authpriv.* /var/log/secure mail.err /var/log/maillog </li></ul><ul><li>Tab delineated file. </li></ul><ul><li>If changes are made need to restart syslog daemon: > kill –HUP `cat /var/run/syslog.pid` </li></ul>
  15. 15. Additional Log Files <ul><li>/var/run/utmp – information about who is currently logged into system. Used by commands such as who and finger . </li></ul><ul><li>/var/log/wtmp – login times and duration for each user on the system. Can view with last command. </li></ul><ul><li>/var/log/lastlog – similar to wtmp but used by different programs, such as finger. </li></ul>
  16. 16. Electronic Mail System Components <ul><li>Mail User Agent (MUA) </li></ul><ul><ul><li>Provides interface for reading mail, writing new messages, and filing. Also called a mailer. </li></ul></ul><ul><ul><li>Examples: mail, Pine, Netscape Mail, Outlook. </li></ul></ul><ul><li>Mail Transport Agent(MTA) </li></ul><ul><ul><li>Routes mail from one user to another either locally or across systems. </li></ul></ul><ul><ul><li>Uses a transport protocol, usually SMTP (Simple Mail Transport Protocol), to provide the medium for mail transfer. </li></ul></ul><ul><ul><li>Examples: Sendmail, Qmail. </li></ul></ul><ul><li>Mail Delivery Agent (MDA) </li></ul><ul><ul><li>Takes a message once received at a site and gets it to the appropriate user mailbox. </li></ul></ul><ul><ul><li>Examples: procmail, mail. </li></ul></ul>
  17. 17. Sample Exchange: Sending, Receiving and Retrieving Electronic Mail Workstation Workstation POP Server SMTP 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
  18. 18. SMTP <ul><li>The SMTP protocol defines the method by which mail is sent from one host to another. </li></ul><ul><li>SMTP usually uses port 25 – mail servers will be “listening” for incoming mail messages. </li></ul><ul><li>No authentication required to use SMTP services – anybody can send mail without providing a username/password to send it. </li></ul>
  19. 19. Sample SMTP Exchange with a Mail Server <ul><li>amenti 5.5 [~] > telnet internet.rutgers.edu 25 </li></ul><ul><li>Trying </li></ul><ul><li>Connected to iti.Rutgers.EDU. </li></ul><ul><li>Escape character is '^]'. </li></ul><ul><li>220 iti.rutgers.edu ESMTP Sendmail 8.9.3/8.8.7; Mon, 15 May 2000 20:32:48 -0400 </li></ul><ul><li>helo foobar.com </li></ul><ul><li>250 iti.rutgers.edu Hello amenti.rutgers.edu [], pleased to meet you </li></ul><ul><li>mail from: kkaplan@foobar.com </li></ul><ul><li>250 kkaplan@foobar.com... Sender ok </li></ul><ul><li>rcpt to: kkaplan@rci.rutgers.edu </li></ul><ul><li>551 we do not relay </li></ul><ul><li>rcpt to: kkaplan@internet.rutgers.edu </li></ul><ul><li>250 kkaplan@internet.rutgers.edu... Recipient ok </li></ul><ul><li>data </li></ul><ul><li>354 Enter mail, end with &quot;.&quot; on a line by itself </li></ul><ul><li>This is a test. </li></ul><ul><li>. </li></ul><ul><li>250 UAA03425 Message accepted for delivery </li></ul>
  20. 20. Exercise: Sending a Message <ul><li>Log into iti.rutgers.edu using ssh. </li></ul><ul><li>Telnet to port 25 on your iti.rutgers.edu: > telnet iti.rutgers.edu 25 </li></ul><ul><li>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> ] </li></ul><ul><li>Verify that your message was received: > less /var/spool/mail/youritiname </li></ul><ul><li>Try reading the message in pine. type: > pine Access your inbox. What information about the message is hidden from the typical user view? </li></ul>
  21. 21. Sendmail <ul><li>Can be downloaded from http://www.sendmail.org . </li></ul><ul><li>Started from /etc/rc.d/init.d/sendmail at boot time. </li></ul><ul><li>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. </li></ul>
  22. 22. Sendmail Components <ul><li>/usr/sbin/sendmail Sendmail binary. Started by default with options –bd –q1h. Sendmail is started by an rc script when system boots. </li></ul><ul><li>/etc/sendmail.cf Main configuration file. Defines rule sets that dictate Sendmail's behavior. Often also points to other sendmail configuration files in /etc. </li></ul><ul><li>/etc/aliases or /etc/mail/aliases Used to create mailing lists or to give users alternative email address. </li></ul><ul><li>/var/spool/mqueue Queue for outgoing email messages. </li></ul>
  23. 23. Receiving Electronic Mail <ul><li>The default storage location for incoming mail is /var/spool/mail/username . </li></ul><ul><li>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. </li></ul>
  24. 24. Aliases File <ul><li>Entry format: username: newuser groupname: user1, user2 </li></ul><ul><li>Sample enties: root: kkaplan@internet.rutgers.edu staff: kkaplan,jsmith,jdoe </li></ul><ul><li>After editing /etc/aliases, for changes to take effect, need to run: > /usr/bin/newaliases </li></ul>
  25. 25. Exercise: Creating Aliases <ul><li>Add the following entries to /etc/aliases: root: student, youremail@domain.com </li></ul><ul><li>Type: > /usr/bin/newaliases </li></ul><ul><li>Verify that your aliases are working: > echo “checking aliases” |/bin/mail root > cat /var/spool/mail/student </li></ul>
  26. 26. Retrieving and Reading Email <ul><li>SMTP is a transport mechanism for sending mail only. An SMTP server will not allow a user to read or retrieve his/her mail. </li></ul><ul><li>Options for reading or retrieving email: </li></ul><ul><ul><li>Use a MUA to access directly the file system where the incoming mail is stored. </li></ul></ul><ul><ul><li>Post Office Protocol (POP) – permits mail to be downloading from a POP server to a POP client. </li></ul></ul><ul><ul><li>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. </li></ul></ul>
  27. 27. POP3 <ul><li>Uses a server process to handle requests to retrieve email. </li></ul><ul><li>Usually uses port 110. </li></ul><ul><li>Unlike SMTP, POP is an authenticated protocol. (users must provide a username and password to retrieve mail) </li></ul><ul><li>Installed by default and enabled on most UNIX systems </li></ul>
  28. 28. IMAP <ul><li>Very similar to POP – however, not yet as popular. </li></ul><ul><li>Uses a server process to handle requests to retrieve email. </li></ul><ul><li>Usually uses port 143. </li></ul><ul><li>IMAP is an authenticated protocol. (users must provide a username and password to retrieve mail) </li></ul><ul><li>Installed by default and enabled on most UNIX systems. </li></ul>
  29. 29. Job Scheduling in UNIX <ul><li>Sometimes its desirable to schedule an application or script to execute unattended at a certain time of day or at a certain frequency. </li></ul><ul><ul><li>System backups (backup the /home filesystem to tape every night at 2:00am) </li></ul></ul><ul><ul><li>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) </li></ul></ul><ul><ul><li>Scripts that mail reports or log files (email me the last 200 lines of the system security log every morning) </li></ul></ul><ul><li>UNIX administrators need a reliable way to schedule unattended jobs and, possibly, give users the ability to schedule unattended jobs. </li></ul>