linux 查看shell执行的定时器

mac2024-04-15  40

1、编辑命令

       1)、在命令行输入: crontab -e 然后添加相应的任务,wq存盘退出

       2)、直接编辑/etc/crontab 文件,即vi /etc/crontab,添加相应的任务

文件位置 /var/spool/cron/

日志文件位置 /var/log

#ls /var/log/cron*

错误日志 当crond执行任务失败时会给用户发一封邮件

可以将每条crontab中的任务增加自己的日志,便于查找执行失败原因。

eg:6 * * * * /home/stack/test.sh >>/mylog.log 2>&1检查crontab服务状态

服务管理 /etc/init.d/crond status

/etc/init.d/crond restart

/etc/init.d/crond start/stop/restart/reload

crontab定时任务最小执行时间

1分钟

如需要小于1分钟,可通过使用延时来实现每N秒执行或编写shell脚本实现

SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/home */2 * * * * sh b.sh

 

最新回复(0)