Tuesday, February 19, 2008

Cron: The Gentleman's Gentleman

(Reproduced from The Furtive Penguin)


Putting Cron To Use On The Desktop

Cron can be very intimidating for new Linux users. It can only be used from the command line and for some unfathomable reason most Linux distributions insist on opening users crontabs with a command line editor.... sometimes nano, sometimes vi. Either one requires an hour long tutorial in order to achieve basic competence. The easisest way to tame it is to open your .bashrc file and insert the following line:-

export EDITOR=gedit

The .bashrc file lives in your home folder and can viewed be checking "Show Hidden Files" in the 'View' menu in Nautilus. Open it with gedit and insert the above line. This ensures that when you type crontab -e in the terminal to access your crontab file it will always open with gedit. There is no easier way to learn than by example so without further ado I proudly present my own crontab file for your delight and delectation:-



# m h dom mon dow command

5 12 * * * rm /home/userone/.thumbnails/normal/*

5 12 * * * rm /home/userone/.thumbnails/fail/gnome-thumbnail-factory

5 12 * * * rm /home/userone/.xsession-errors

5 12 * * * rm /home/userone/.recently-used

10 12 * * * du -h /home/userone/dback | tee /home/userone/Desktop/duback

5 22 * * * /home/userone/backup


( see 'Examples' below for an explanation of these commands )


The abbreviations in the first line above translate as follows:-


Minute Hour Day Month Day of the week Command

Values for these fields are entered according to the following table:-

1. Minute [0,59]

2. Hour [0,23]

3. Day of the month [1,31]

4. Month of the year [1,12]

5. Day of the week ([0,6] 0=Sunday)

Simple, right? Well not exactly. Cron entries can take some getting used to and the whole procedure is easily forgotten if you dont use it regularly. Fortunately there are a number of sites which will generate your cron entries for you from the comfort of the web browser of your choice. Take your pick from the following list:-


Clockwatchers

Csgnetwork

Alternatively you might elect to use one of the many GUI front-ends that are available for the cron command :-

Kcron

Gcrontab ( also available in the Ubuntu repositoiries )

Vcron

The manual page for cron can be found here.

Of course theres much more to say about cron. You might even choose to discard it altogether in favor of fcron which is an updated and more sophisticated version of the basic program. If you run a server its uses are legion and your crontab file will rapidly become one of your main administrative tools. But, mastering the basics for everyday desktop use need not be too much of a chore and ultimately it will pay dividends in terms of saved time and increased efficiency.

Please visit our suggestions page for some ideas for useful things to do with cron on the desktop.