A Linux crontab mail command example

Linux crontab mail FAQ: Can you share an example of a Linux crontab entry you use to send email on a regular basis?

Here's the source code for a really simple Linux mail script that I used to send an email message to one of my co-workers every month. This script used the Unix or Linux mail command to email a file to her that showed a list of all the websites on our server that she needed to bill our customers for.

Here's the source code for the email shell script:


# cd to the directory that contains the file we want to email
cd /web/sites

# send the email with the unix/linux mail command
mail -s "Current customer directories" kim@example.com < listOfWebSites.txt

As you might guess from looking at that mail command, the "Current customer directories" string is the subject of the email message, and listOfWebSites.txt is the file that was sent via email to a person named Kim. The string "kim@example.com" shows where the recipient's email address belongs in the mail command.

My Linux crontab mail entry

Next, here's my crontab entry that corresponds to this Linux email script:

0 5 1 * * /home/al/bin/mailWebSitesToKim.sh

If you're familiar with the Unix/Linux crontab syntax, you can see that this command sends this email message once every month, at 5 a.m. on the first day of the month.

More crontab information

If you're not familiar with the crontab file format, here are a few links to some of our crontab content:

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.