cron job application code example
Example 1: cron example
crontab -e # to edit
10 * * * * /bin/sh backup.sh # every hour at 10"
0 */4 * * * /bin/sh backup.sh # every 4 hours at 0"
0 9-17 * * * /bin/sh backup.sh # every hour at 0" between 9 and 17
0 2 * * * /bin/sh backup.sh # daily at 2am
0 0 * * MON /bin/sh backup.sh # every Monday at 0am
0 0 * * 1-5 /bin/sh backup.sh # daily from Monday to Friday at 0am
0 0 * * 0 /bin/sh backup.sh # weekly on Sunday
0 0 1 * * /bin/sh backup.sh # monthly (1rst day at 0am)
0 0 1 */3 * /bin/sh backup.sh # every quarter (1rst day at 0am)
0 0 1 1 * /bin/sh backup.sh # yearly (01/01)
Example 2: create cron job from command line
#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo "00 09 * * 1-5 echo hello" >> mycron
#install new cron file
crontab mycron
rm mycron