Now that we have looked at the basics of cron, how would you set up an entry to run a command every other week? You may be tempted to try something like the following code:
* * * * 0/2 /path/command
That means to start on Sunday, and then run every other Sunday, right? No, this is wrong, but you often see this given as a solution on websites. Cron doesn't actually have a built-in way to do this, but there is a work-around.
The following are the steps to run a command every other week:
Create the following script in your home directory and name it
cron-weekly1
(feel free to cut and paste):#!/bin/sh # cron-weekly1 # Use this script to run a cron job every other week FN=$HOME/cron-weekly.txt if [ -f $FN ] ; then rm $FN exit fi touch $FN echo Run the command here
Make the script executable by running the following command:
chmod 755 cron-weekly1
Under your user account run by running the following command:
crontab -e
Add...