前言
【linux定时任务contab】本文介绍如何通过LINUX定时执行一个脚本,执行的脚本文件如下vim do.sh::
#!/bin/bash
echo $(date -R) >> /home/test/hello.txt
crontab -e * * * * * sh /home/test/do.sh
[root@localhost test]# tail -f hello.txt
Mon, 09 Jul 2018 12:57:02 +0800
Mon, 09 Jul 2018 12:58:01 +0800
Mon, 09 Jul 2018 12:59:01 +0800
Mon, 09 Jul 2018 13:00:01 +0800
Mon, 09 Jul 2018 13:01:01 +0800
Mon, 09 Jul 2018 13:02:01 +0800
Mon, 09 Jul 2018 13:03:01 +0800
crontab -e */2 * * * * sh /home/test/do.sh
/etc/init.d/crond restartdo.shhello.txt
[root@localhost test]# tail -f hello.txt
Mon, 09 Jul 2018 13:10:01 +0800
Mon, 09 Jul 2018 13:12:01 +0800
Mon, 09 Jul 2018 13:14:01 +0800
yum install crontabs
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
/sbin/service crond status //启动服务
ntsysv
chkconfig –level 35 crond on
date -s "2018-12-12 01:00:00"修改时间,更快验证脚本有效性;