ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
一、cron服务   cron是一个linux下 的定时执行工具,可以在无需人工干预的情况下运行作业。   service crond start //启动服务   service crond stop //关闭服务   service crond restart //重启服务   service crond reload //重新载入配置   service crond status //查看服务状态 二, 要把cron设为在开机的时候自动启动,在 /etc/rc.d/rc.local 脚本中加入 /sbin/service crond start 即可 查看当前用户的crontab,输入 crontab -l; 编辑crontab,输入 crontab -e; 删除crontab,输入 crontab -r 三。 基本格式 : *  *  *  *  *  command 分 时 日 月 周 命令 第1列表示分钟1~59 每分钟用*或者 */1表示 第2列表示小时1~23(0表示0点) 第3列表示日期1~31 第4列表示月份1~12 第5列标识号星期0~6(0表示星期天) 第6列要运行的命令 crontab文件的一些例子: 30 21 * * * /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每晚的21:30重启apache。 45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每月1、10、22日的4 : 45重启apache。 10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每周六、周日的1 : 10重启apache。 0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart 上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。 0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart 上面的例子表示每星期六的11 : 00 pm重启apache。 * */1 * * * /usr/local/etc/rc.d/lighttpd restart 每一小时重启apache * 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart 晚上11点到早上7点之间,每隔一小时重启apache 0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart 每月的4号与每周一到周三的11点重启apache 0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart 一月一号的4点重启apache 四,脚本文件 touch delta.sh touch delta.log 六。权限 在所在目录执行命令 chmod a+x * 五,样例 1.delta.sh #!/bin/bash #test1.sh indexer test1 --rotate>>/home/mysql/sphinx/log/test1.log 2.crontab -e */10 * * * * /home/mysql/sphinx/init/delta.sh 00 03 * * * /home/mysql/sphinx/init/test1.sh