🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 执行权限 ``` chmod u+x script.sh ``` ## 执行日志 ``` #/bin/bash exec &> /root/log/script.log ... ``` ## 定期执行 cat /etc/crontab ``` SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed ``` 每5分钟执行一次脚本 ``` */5 * * * * root /root/scripts/backup.sh ``` 脚本锁定执行(确保本次脚本100%执行完毕后,才启动下一次脚本执行) ``` */5 * * * * root flock -xn /dev/backup.lock -c "/root/scripts/backup.sh" ```