官术网_书友最值得收藏!

Understanding crontab

If we need to run a specific task repetitively, then the solution is to use crontab. The syntax of the command is as follows:

    $ crontab -e

This will open a new editor. The following diagram is the syntax to add tasks. The fields to use for repeating tasks at a particular time are explained here:

Finally, to save the jobs, use the following:

    Press Esc then type :wq
    

The preceding operations will save the job and quit crontab.

The following are a few examples of the crontab command:

  • Use the following command to run a script every hour at the fifth minute, every day:
    5 * * * *      $HOME/bin/daily.job >> $HOME/tmp/out  2>&1
  • Use the following command to run 5 minutes after midnight every day:
    5 0 * * *      $HOME/bin/daily.job >> $HOME/tmp/out  2>&1
  • Use the following command to run at 2.15 p.m. on the first of every month–the output is mailed to Paul:
    15 14 1 * * *     $HOME/bin/monthly
  • Use the following command to run at 10 P.M. on weekdays, and send the email to ganesh@abc.com:
    0 22 * *  1-5   sendmail ganesh@abc.com  < ~/work/email.txt
  • The sendmail utility is used for sending emails. We can also use the mail utility as follows:
    sendmail user@example.com  < /tmp/email.txt
  • The following commands are self-explanatory from the text of the echo command:
    23 0-23/2  *  *  *  echo "run 23 minutes after midn, 2 am, 4 am, everyday"
    5  4  *  *  sun    echo "run at 5 minutes after 4 am every Sunday"

The following are a few more crontab command examples:

主站蜘蛛池模板: 黄陵县| 茶陵县| 邓州市| 城市| 奉节县| 盖州市| 会宁县| 怀宁县| 东方市| 石家庄市| 神农架林区| 铁岭市| 平武县| 仲巴县| 堆龙德庆县| 岳西县| 栾川县| 云阳县| 临沭县| 遂溪县| 溧阳市| 上栗县| 靖安县| 澄江县| 广安市| 云浮市| 美姑县| 凭祥市| 大埔县| 宁化县| 延寿县| 东乌珠穆沁旗| 富民县| 赣州市| 德安县| 长治市| 四川省| 兴化市| 城步| 韶关市| 汉沽区|