使用crontab定时执行脚本

使用crontab定时执行脚本

  • 查看是否安装crontab

whitch crontab

  • 编写脚本,并给脚本读权限(很重要)

vi test.sh

chmod +x test.sh

  • 使用root权限打开/etc/crontab,设置定时任务

00 01 * * * cd /home && sh test.sh >> /home/log 意思是每天1:00开启执行脚本,并把日志重定向到日志文件

  • 重新载入配置

service crond reload

  • 传入时间参数:
0 0 * * * /home/test.sh $(date -d "1 day ago" +"\%Y-\%m-\%d") >> /home/log

 


版权声明:本文为weixin_47551373原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。