首页 > 系统服务 > 详细

linux 计划任务 crontab 简单用法

时间:2018-06-13 13:48:19      阅读:154      评论:0      收藏:0      [点我收藏+]

添加计划任务:

方法1:
crontab -e

方法2:
vim /etc/crontab  #这种方式进去的文件有个sample可供参考
查看已经启动的任务:
crontab -l

查看运行状态:
service crond status
/sbin/service crond start
/sbin/service crond stop
/sbin/service crond restart
/sbin/service crond reload
以上1-4行分别为启动、停止、重启服务和重新加载配置。

要把cron设为在开机的时候自动启动,在 /etc/rc.d/rc.local 脚本中加入 /sbin/service crond start 即可

查看当前用户的crontab,输入 crontab -l;

编辑crontab,输入 crontab -e;

删除crontab,输入 crontab -r

查看cron的log日志文件:

tailf /var/log/cron

重启crond服务:

service crond restart
参考:https://www.cnblogs.com/cuisi/p/6251848.html

【crontab的环境变量问题】
1.脚本中:直接使用mysql命令 命令:手动执行脚本,正常输出文件。因为:/etc/profile 中加入 了系统环境变量:/usr/local/mysql/bin/ 2.crontab执行:如果想成功执行 分两种情况: 1.脚本中mysql命令指定绝对路径:/usr/local/mysql/bin/mysql 2.将mysql可执行文件复制到:crontab的环境变量指定的路径中 ------------------------------------------------------ # crontab的配置文件!!!

------------------------------------------------------
[root@monitor2 scripts]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin # 将mysql可执行文件复制到/usr/bin下,脚本中就可以直接使用mysql命令
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
-------------------------------------------------------------

 

linux 计划任务 crontab 简单用法

原文:https://www.cnblogs.com/gavinyyb/p/9176936.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!