crontab定时任务的配置

论坛 期权论坛 脚本     
匿名技术用户   2021-1-2 04:02   26   0

crontab命令的解释

crontab: usage error: unrecognized option 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)

主要用到三个option以及相关的操作

一 新建自己的执行脚本

root@DELL-XPS13-VIC:/home/visco/testdir# pwd /home/visco/testdir root@DELL-XPS13-VIC:/home/visco/testdir# ls dateprint.log ss.sh root@DELL-XPS13-VIC:/home/visco/testdir# vi ss.sh

编辑任务

#!/bin/sh date -d now>dateprint.log


Esc

:wq

配置定时任务

crontab -e

# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command
* * * * * cd /home/visco/testdir && ./ss.sh

检查配置的任务

crontab -l

重启crontab服务

/etc/init.d/cron restart

查看运行情

tailf /home/visco/testdir/dateprint.log

2017年 04月 01日 星期六 09:36:01 DST 2017年 04月 01日 星期六 09:37:01 DST 2017年 04月 01日 星期六 09:38:01 DST 2017年 04月 01日 星期六 09:39:01 DST 2017年 04月 01日 星期六 09:40:01 DST 2017年 04月 01日 星期六 09:41:01 DST 2017年 04月 01日 星期六 09:42:01 DST 2017年 04月 01日 星期六 09:43:01 DST 2017年 04月 01日 星期六 09:44:01 DST



分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP