Recent Changes - Search:
NTLUG

Linux is free.
Life is good.

Linux Training
10am on Meeting Days!

1825 Monetary Lane Suite #104 Carrollton, TX

Do a presentation at NTLUG.

What is the Linux Installation Project?

Real companies using Linux!

Not just for business anymore.

Providing ready to run platforms on Linux

Created by Terry Henderson on April 08, 2010, at 06:37 PM

Most desktop users don't use crontab because it seems too hard and they just don't find a task worthy of such a complicated process. It seems complicated at first, but once you've made an entry or two it's easy and seeing a few examples will break the ice. To edit/create crontab jobs, simply issue command

crontab -e

And I think most systems just use the vi editor. (There is an interactive turotial: vimtutor Or here is a really good article from Linux Journal: http://www.linuxjournal.com/article/6542 )

Here's a very simple one. This one is a root corontab job to keep the time accurate:
0 3 * * 0 /usr/sbin/ntpdate pool.ntp.org
It's sometimes helpful to put notes above entries that explain what it's for, especially at first when you're learning, so that when you come back to it you'll see at a glance what you really meant to do. If the job is not working right, you'll know what the original intention was, and it will help you remember the syntax and revise and/or more easily figure out how to make the next one.
# Reset time at 3AM each Sunday (0=Sunday 6=Saturday)
0 3 * * 0 /usr/sbin/ntpdate pool.ntp.org

It's all pretty simple actually; There are only 6 fields separated by spaces and they are in a specific order. (See image at bottom for more details.)

  1     2      3       4      5        6

minute hour day-of-month month day-of-week command

Here are some examples for Desktop Users:
#Remind me to watch Larry King @8PM on Thursday
55 19 11 03 4 flite “Larry King comes on in 5 minutes”
56 19 11 03 4 DISPLAY=:0.0 xmessage "Larry King @ 8 PM"
So that gives us two reminders, one audio, one visual. If we miss the visual one, the audio might just catch our attention. Let's look at a few more.

Here are more examples, ones I've actually set up for my mother-in-law:
# MIN HOUR DAY MONTH DAYOFWEEK COMMAND
0 9 * * * DISPLAY=:0.0 xmessage "Time for your breathing treatment: 9AM"
0 15 * * * DISPLAY=:0.0 xmessage "Time for your breathing treatment: 3PM"
0 21 * * * DISPLAY=:0.0 xmessage "Time for your breathing treatment: 9PM"
0 9,15,21 * * * play /home/marge/messages/breathing-treatment-reminder.mp3
54 13 * * sat DISPLAY=:0.0 xmessage "Bishop Fulton Sheen starts in five minutes."
55 13 * * sat play /home/marge/messages/Fulton-Sheen-Reminder.mp3
0 14 * * sat DISPLAY=:0.0 XAUTHORITY=/home/marge/.Xauthority /usr/bin/vlc http://viewers.multicastmedia.com/asx_files/EWTN_Channel55_English_DomesticEnglish_500k.asx
30 15 * * sat /usr/bin/pkill vlc
0 11 * * sun DISPLAY=:0.0 XAUTHORITY=/home/marge/.Xauthority /usr/bin/vlc http://webcastingnetworks.easycgi.com/fumcfw/fumcfwlive.asx
0 12 * * sun /usr/bin/pkill vlc
0 11 2-6 04 * DISPLAY=:0.0 xmessage "No Plavix today, Dental apt. is on Wednesday"
1 11 6 04 tue DISPLAY=:0.0 xmessage "Dental appointment is tomorrow at 8AM"
30 06 7 04 wed play /usr/share/sounds/k3b_success1.wav ; play /usr/share/sounds/k3b_success1.wav ; play /usr/share/sounds/k3b_success1.wav ; play /usr/share/sounds/k3b_success1.wav
0 11 8 04 4 DISPLAY=:0.0 DISPLAY=:0.0 xmessage "Start taking Plavix again."
30 11,21 8-18 04 * DISPLAY=:0.0 xmessage "Take your penicillin"
31 11,21 8-18 04 * flite "Time to take your penicillin"
0 12 9 04 5 DISPLAY=:0.0 DISPLAY=:0.0 xmessage "Watch for UPS delivery today"


trryhend@gmail.com
Back to Site Blogs

Page last modified on April 10, 2010, at 11:31 AM