Crontab

The crontab is a useful tool to aid in performing tasks at specified times in linux and solaris. First off is understanding how to view the crontab for your user. Open up a Terminal window and run the command:

crontab -l

You’ll get something like the following if you have nothing:

no crontab for ryan

Now let’s learn how to edit the crontab. The command to edit your crontab entry is:

crontab -e

Now this will use whatever default editor is set for you. To set your own favorite editor, we’ll export out the EDITOR variable:

export EDITORY=vi

crontab -e

and voila, I’m editing my crontab entry with my favorite text editor vi.

Wikipedia has a great article and explains the fields of an entry. So for the crontab entry for root on my linux machine, it looks like:

# m h dom mon dow   command
0 2 * * * /sbin/poweroff

So the # means a comment, I usually put that line in to remind me the syntax and the second line is my entry. This reads: At 0 minutes, hour 2, every day of the month, every month of the year, and everyday of the week, do /sbin/poweroff.

I tend to fall asleep and accidentally leave my computer on, so this works great to turn off my computer at 2am everyday. There are some other tools that can be used to turn off computers when idle or at certain times, but I find this solution simple and easy.

This entry was posted in software and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *