Editing 1728: Cron Mail

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 8: Line 8:
  
 
==Explanation==
 
==Explanation==
On {{W|Unix}}-like systems, {{W|Cron|cron}} is a system utility that runs tasks on a schedule. This program has been around since the early days of Unix and has not changed much - it is still one of the most widely used functions in modern operating systems. Many administrative tasks on servers are automated using cron, including monitoring and updates.
+
{{incomplete|Format information, the bottom two paragraphs should be at the top. Also shorten and simplify explanation.}}
 +
On {{W|Unix}}-like systems, {{W|Cron|cron}} is a system program running in background which allows one to schedule jobs to run at well-defined time slots. It is conceptually the same software which has been used since, at least, the 1980s and is still heavily used in modern operating systems, for example in several {{w|Linux}} distributions. Many administrative tasks on servers can be automated with cron, like monitoring or updates. Most people administrating a server-like system with a UNIX-like operating system will therefore know it, at least the basics.
  
When a cron job produces output, cron's default behavior is to send an email to the user account under which the job ran. However, in most situations, an email address has not been set up for that user, so the email is instead written to a mailbox file. Most Unix shells will notify the user with a message like "You have new mail" when this mailbox file is updated, but if the user doesn't know how to check this mail file, they will likely just ignore the message.
+
When one of these jobs produces output, that output is sent as an email to the user, using the {{w|Sendmail|sendmail}} program. A common situation on many Unix-like systems is that sendmail (or another email program) is not configured to send email to the actual email address of the person behind the user account that configured the cron job, and writes the mail in question to the file <code>/var/mail/username</code> (in {{w|Mbox|mbox}} format) instead. Most shells will check that file, and produce a message "You have new mail" when its timestamps have changed; however, if a person doesn't know how to check their mail they will likely end up just ignoring that message.
  
In this case, Cueball has been ignoring his mailbox for fifteen years.  When he finally learns where to look, he discovers more than a gigabyte worth of messages from the cron program, the vast majority of which are likely meaningless.  Ponytail says to Cueball "fix your cron" (likely meaning he should fix the task that's generating the output so that it doesn't do so), then set a parameter that tells cron to send email to an address he actually checks.  (He could also opt to direct the mails to <code>/dev/null</code>, which would discard them, or simply disable the mail in the crontab.)  Cueball, however, interprets the tremendous amount of email as spam and decides to redirect the emails to <code>/etc/crontab</code>, the main configuration file that contains all of cron's scheduling information.  He apparently believes that this will either stop the emails or cause cron to spam itself instead.
+
The "/etc" directory is used for configuration files on UNIX-systems; therefore "/etc/crontab" is the main configuration file of cron and is expected to contain lines such as the following:
  
In reality, this will not cause significant problems as the <code>MAILTO</code> environmental variable in cron takes an email address or usernames on the local system and attempts to send emails to them. It will not write or append output to a local file like <code>/etc/crontab</code>.  Thus when cron attempts to email <code>/etc/crontab</code> the mail program cron uses will generate an error saying it can't find the user <code>/etc/crontab</code>.  
+
  #m h dom mon dow user  command
 +
17 *  *  *  *  root  cd / && run-parts --report /etc/cron.hourly
  
For example, if you create the following crontab:
+
Comment lines are designated by a # and are ignored, as are blank lines.  On a non-comment non-blank line, the first 5 parameters tell it exactly when that line is supposed to run (in this case every hour on the 17th minute of the hour), the next part is what user the command is supposed to run as (root in this case), and the rest is the actual command that is supposed to run (cd / && run-parts --report /etc/cron.hourly).  The 5 time parameters, in order are minutes, hours, day-of-month, month, and day-of-week.  A * means everything matches.  So something could run as frequently as every minute (* * * * *) or as infrequently as once a year (i.e. January 2nd at 10:20am is 20 10 2 1 *).  If a line that doesn't follow the correct format is added to /etc/crontab, it may cause the entire crontab file to be ignored, even those entries that are otherwise valid.
  
<pre>
+
When a cron job runs, it is expected to do something with all text that might normally go to the screen -- a lot of times a command will redirect it to a log file of its own, or deliberately make it go nowhere (/dev/null).  If anything does end up "on the screen", cron captures it and sends it as an email to the user, assuming it's data the user wants to view and be aware of.  If local email is not configured to go somewhere the user actually knows to check, it usually ends up tacked on to the end of a file in /var/mail/username where it will sit forever, or until the user actually does something with it (either configures a local email program, sets up a forward to an email account they actually check, or deletes the file).  Ponytail's suggestion to "fix the cron" means figure out why the cron job is outputting data to the screen, which is thus generating an email, and instead having the cron job handle its own messages in a better way.  Once the cron jobs are no longer "talking" all the time, her further suggestion to point the MAILTO= to somewhere else would help Cueball be immediately aware if something goes wrong with a cron job that is normally quiet, so he can address the problem immediately instead of it going on for years undetected.
MAILTO=/etc/crontab
 
  
* * * * * echo "Some output from a cronjob"
+
[[Cueball]] is not aware of all of the above, and expresses surprise at the repeated messages. [[Ponytail]] tells him to check check <code>/var/mail/cueball</code> which contains a lot of messages from cron from all those 15 years he used cron without properly understanding how it works.
</pre>
 
  
installed on a user named <code>me</code> on a system called <code>mycomputer</code> then you will see a new error messages email to you (located in <code>/var/mail/me</code>) stating it can't send email to a user named <code>/etc/crontab</code> and the undelivered email is being returned to the sender. The error email will look like the following:
+
When he realizes what has happened, he configures the mail system so that it writes all mail for his user to the <code>/etc/crontab</code> file, which is the main configuration file of cron (the <code>{{W|/etc}}</code> directory is used for configuration files on Unix-like systems), most probably breaking it.  Of course, none of the jobs normally scheduled to run will run anymore either, so he will likely be surprised when other things that used to work no longer work.  There are a number of system cron jobs that are usually present on Linux and Unix-like systems that one would not want to disable, including checking for updates, rotating log files including deleting old logs files, backups, etc.
  
<pre>
+
In the worst case, cron might actually see the junk that [[Cueball]] is now directing into its configuration as valid configuration data and produce even more mail – resulting in a feedback situation that would eventually fill up the disk partition. It's unclear (especially to [[Cueball]]) whether this is actually possible – but it's certainly a risk.
From MAILER-DAEMON  Tue Sep  6 14:47:01 2016
 
Return-Path: <>
 
X-Original-To: [email protected]
 
Delivered-To: [email protected]
 
Received: by mycomputer.local (Postfix)
 
        id 5341C64EE516; Tue, 6 Sep 2016 14:47:01 -0400 (EDT)
 
Date: Tue,  6 Sep 2016 14:47:01 -0400 (EDT)
 
From: MAILER-DAEMON@mycomputer.local (Mail Delivery System)
 
Subject: Undelivered Mail Returned to Sender
 
 
Auto-Submitted: auto-replied
 
MIME-Version: 1.0
 
Content-Type: multipart/report; report-type=delivery-status;
 
        boundary="33AF864EE514.1473187621/mycomputer.local"
 
Message-Id: <20160906184701.5341C64EE516@mycomputer.local>
 
  
This is a MIME-encapsulated message.
+
The Title Text shows that Cueball is somewhat aware of what cron does, including the fact that it's existed pretty much unchanged for several decades, but he hasn't bothered to really get into understanding it, treating it more as a foe to vanquish rather than as a tool to understand and use.
 
 
--33AF864EE514.1473187621/mycomputer.local
 
Content-Description: Notification
 
Content-Type: text/plain; charset=us-ascii
 
 
 
This is the mail system at host mycomputer.local.
 
 
 
I'm sorry to have to inform you that your message could not
 
be delivered to one or more recipients. It's attached below.
 
 
 
For further assistance, please send mail to postmaster.
 
 
 
If you do so, please include this problem report. You can
 
delete your own text from the attached returned message.
 
 
 
                  The mail system
 
 
 
</etc/[email protected]> (expanded from </etc/crontab>): unknown user:
 
    "/etc/crontab"
 
 
 
--33AF864EE514.1473187621/mycomputer.local
 
Content-Description: Delivery report
 
Content-Type: message/delivery-status
 
 
 
Reporting-MTA: dns; mycomputer.local
 
X-Postfix-Queue-ID: 33AF864EE514
 
X-Postfix-Sender: rfc822; [email protected]
 
Arrival-Date: Tue,  6 Sep 2016 14:47:00 -0400 (EDT)
 
 
 
Final-Recipient: rfc822; /etc/[email protected]
 
Original-Recipient: rfc822; /etc/crontab
 
Action: failed
 
Status: 5.1.1
 
Diagnostic-Code: X-Postfix; unknown user: "/etc/crontab"
 
 
 
--33AF864EE514.1473187621/mycomputer.local
 
Content-Description: Undelivered Message
 
Content-Type: message/rfc822
 
 
 
Return-Path: <[email protected]>
 
Received: by mycomputer.local (Postfix, from userid 501)
 
        id 33AF864EE514; Tue,  6 Sep 2016 14:47:00 -0400 (EDT)
 
From: [email protected] (Cron Daemon)
 
 
Subject: Cron <me@mycomputer> echo "Some output from a cronjob"
 
X-Cron-Env: <MAILTO=/etc/crontab>
 
X-Cron-Env: <SHELL=/bin/sh>
 
X-Cron-Env: <PATH=/usr/bin:/bin>
 
X-Cron-Env: <LOGNAME=me>
 
X-Cron-Env: <USER=me>
 
X-Cron-Env: <HOME=/Users/me>
 
Message-Id: <[email protected]>
 
Date: Tue,  6 Sep 2016 14:47:00 -0400 (EDT)
 
 
 
Some output from a cronjob
 
 
 
--33AF864EE514.1473187621/mycomputer.local--
 
</pre>
 
 
 
 
 
The title text shows that Cueball is somewhat aware of what cron does, including the fact that it's existed pretty much unchanged for several decades, but he hasn't bothered to really get into understanding it, treating it more as a foe to vanquish rather than as a tool to understand and use.
 
  
 
==Transcript==
 
==Transcript==

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)