Simple cron example
Simple cron example (tested on Ubuntu):
- Edit your (user) crontab file
$ crontab -e
This will bring up your editor (nano by default in Ubuntu)
- Enter the following inside. This will append the current date to a log file every minute. The 6 fields of the crontab file are: minute, hour, day of month, month, day of week, command.
* * * * * /bin/date >> /tmp/cron_output
Be sure to put a newline at the end of the file.
(NOTE 1:>>only redirects STDOUT to a file. To redirect both STDOUT and STDERR, use something like/bin/date >> /tmp/cron_output 2>&1)
(NOTE 2: If output is not redirected, cron will try to email the output to you. To do this, a mail transfer agent such as sendmail or postfix must be installed.)
- Exit the editor. It should output:
crontab: installing new crontab
- Check that it is working:
tail -f /tmp/cron_output
You should see the date updated every minute on the minute (or close to it):Tue Sep 16 23:58:01 PDT 2008 Tue Sep 16 23:59:01 PDT 2008 Wed Sep 17 00:00:01 PDT 2008 Wed Sep 17 00:01:01 PDT 2008 ...
1
Comment
—
Comments feed for this post
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(4)
-
aws
(8)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(9)
-
conkeror
(2)
-
cygwin
(18)
-
datastructures
(15)
-
datetime
(3)
-
dell
(3)
-
django
(39)
-
emacs
(20)
-
files_directories
(10)
-
install_setup
(7)
-
javascript
(3)
-
keyboard
(6)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
preferences
(8)
-
processes
(3)
-
pyqt
(18)
-
python
(122)
-
ratpoison
(3)
-
regexes
(5)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(13)
-
ssh
(7)
-
subversion
(6)
-
twisted
(6)
-
ubuntu
(60)
-
urxvt
(5)
-
vxworks
(25)
-
webservices
(4)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan
#1 haimeika commented on 2009-06-29:
Hi, Sofeng
I am a beginner of linux. The example is very simple but you list the steps very clearly. It is so helpful for me, and thank you very much.