- Learning Linux Shell Scripting
- Ganesh Sanjiv Naik
- 290字
- 2021-08-20 10:44:30
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 what time are explained here:

Finally, to save the jobs, use the following:
wq # save and quite crontab job
The following are a few examples of the crontab
command:
- Use the following command to run a script every 5 minutes, 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, send the e-mail to
<ganesh@abc.com>
:0 22 * * 1-5 sendmail ganesh@abc.com < ~/work/email.txt
- The
sendmail
utility is used for sending e-mails. We can use the mail utility also as follows:sendmail user@example.com < /tmp/email.txt
- The following commands are self-explanatory from text of echo:
23 0-23/2 * * * echo "run 23 minutes after midn, 2 am, 4 am, everyday 5 4 * * sun echo "run at 5 after 4 every Sunday"
The following are a few more crontab
command examples:

We can add macros
in the crontab
file. Use the following to restart my_program
after each reboot:
@reboot /bin/my_program @reboot echo `hostname` was rebooted at `date` | mail -s "Reboot notification" ganesh.admin@some-corp.com
The following is the summary of a few more macros:

推薦閱讀
- Developing Mobile Web ArcGIS Applications
- C# 從入門(mén)到項(xiàng)目實(shí)踐(超值版)
- Python 3破冰人工智能:從入門(mén)到實(shí)戰(zhàn)
- GeoServer Beginner's Guide(Second Edition)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲(chóng)案例實(shí)戰(zhàn)全流程詳解(入門(mén)與提高篇)
- Mobile Device Exploitation Cookbook
- Java程序員面試筆試寶典(第2版)
- Go語(yǔ)言編程
- 細(xì)說(shuō)Python編程:從入門(mén)到科學(xué)計(jì)算
- Python機(jī)器學(xué)習(xí)之金融風(fēng)險(xiǎn)管理
- MySQL程序員面試筆試寶典
- Natural Language Processing with Python Quick Start Guide
- Mastering Gephi Network Visualization
- NGUI for Unity
- Java RESTful Web Service實(shí)戰(zhàn)