crontab - 定时任务

crontab - 定时任务

我的操作系统版本是CentOS-6

1.查看是否安装

--定时执行任务
crontab [-u user] file crontab [-u user] [ -e | -l | -r ]

--说明没有安装
crontab -e
-bash: crontab: command not found

2.安装(如果没有安装)

--安装
--https://blog.csdn.net/testcs_dn/article/details/48781553
--https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html
rpm -ivh procmail-3.22-25.1.el6_5.1.x86_64.rpm
rpm -ivh hesiod-3.1.0-19.el6.x86_64.rpm
rpm -ivh sendmail-8.14.4-8.el6.x86_64.rpm
rpm -ivh cronie-1.4.4-16.el6_8.2.x86_64.rpm --nodeps
rpm -ivh crontabs-1.10-33.el6.noarch.rpm
rpm -ivh cronie-anacron-1.4.4-16.el6_8.2.x86_64.rpm

3.创建执行任务

输入crontab -e 后,会出现类似vi的界面操作。

任务描述:每一分钟把当前时间信息追加到/root/test/result.log文件中。

crontab -e

* * * * * date >> /root/test/result.log

:wq

4.任务结果

cd /root/test/
tail -f result.log

[root@node1 test]# tail -f result.log 
Sun Jan  6 01:42:01 PST 2019
Sun Jan  6 01:43:01 PST 2019
Sun Jan  6 01:44:01 PST 2019

5.服务状态控制

# service crond start 
# service crond stop 
# service crond restart 
# service crond reload 
# service crond status

6.是否开机启动

--开机启动
vi /etc/rc.d/rc.local

/sbin/service crond start

:wq

7.Reference

https://blog.csdn.net/testcs_dn/article/details/48781553

https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html

========================================================

More reading,and english is important.

I'm Hongten

 

大哥哥大姐姐,觉得有用打赏点哦!你的支持是我最大的动力。谢谢。
Hongten博客排名在100名以内。粉丝过千。
Hongten出品,必是精品。

E | [email protected]  B | http://www.cnblogs.com/hongten

========================================================

猜你喜欢

转载自www.cnblogs.com/hongten/p/hongten_crontab.html