欢迎访问个人网络日志🌹🌹知行空间🌹🌹
crontab
用来设置定时执行Linux
中的任务,其使用也比较简单。
crontab -e
编辑crontab
文件crontab -l
展示crontab
文件crontab -v
查看crontab
文件最近一次修改时间
crontab
文件示例:
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#* * * * * command to be executed
#– – – – –
#| | | | |
#| | | | +—– day of week (0 – 6) (Sunday=0)
#| | | +——- month (1 – 12)
#| | +——— day of month (1 – 31)
#| +———– hour (0 – 23)
#+————- min (0 – 59)
0,15,25 * * * * /home/user/script.sh #每月的25号15时执行/home/user/script.sh
设置某个程序开机自启动
crontab -e
在文件中添加
crontab
中的任务是并行的,不用担心耗时的问题
@reboot /home/user/test.sh
参考资料
- 1.https://www.codementor.io/@akul08/the-ultimate-crontab-cheatsheet-5op0f7o4r
- 2.https://stackoverflow.com/questions/12973777/how-to-run-a-shell-script-at-startup
欢迎访问个人网络日志🌹🌹知行空间🌹🌹