Linux定时任务Crontab使用 提示no crontab for root

使用命令查询crontab 任务时,一直提示:no crontab for root 。查看了一些资料,说是crontab在初始时,设置了一次编辑方式,所以试了一下crontab -e的方式编辑,即在命令行,输入 crontab -e ,进行编辑页面,输入定量执行的脚本

 */1 * * * * root /data/bakdb.sh  > /data/bak.log 2>&1  。crontab -e的使用方式与vi编辑器相同, 配置成功后 使用命令crontab -u root -l 可以查看当前定时任务

具体流程:

cd etc

在etc目录下,执行 crontab -e  

在插入模式下输入 0 1 * * * root /data/bakdb.sh  > /data/bak.log 2>&1

保存

使用命令 crontab -u root -l 可以查看当前定时任务  成功!


crontab命令详解

usage:    crontab [-u user] file
    crontab [ -u user ] [ -i ] { -e | -l | -r }
        (default operation is replace, per 1003.2)
    -e    (edit user's crontab)   
    -l    (list user's crontab)
    -r    (delete user's crontab)
    -i    (prompt before deleting user's crontab)


crontab -e  

crontab -l

crontab实现以秒执行,很好很强大

 linux中crontab实现以秒执行任务

很多时候,我们计划任务需要精确到秒来执行,根据以下方法,可以很容易地以秒执行任务。
以下方法将每10秒执行一次
1.编辑crontab
crontab -e
* * * * * /bin/date >>/tmp/date.txt
* * * * * sleep 10; /bin/date >>/tmp/date.txt
* * * * * sleep 20; /bin/date >>/tmp/date.txt
* * * * * sleep 30; /bin/date >>/tmp/date.txt
* * * * * sleep 40; /bin/date >>/tmp/date.txt
* * * * * sleep 50; /bin/date >>/tmp/date.txt
2.检查结果
tail -f /tmp/date.txt
原文地址:https://www.cnblogs.com/SofuBlue/p/8283597.html