Linux 计划任务 访问网页

1.linux安装

[root@CentOS ~]# yum -y install vixie-cron
[root@CentOS ~]# yum -y install crontabs

说明:
vixie-cron 软件包是 cron 的主程序;
crontabs 软件包是用来安装、卸装、或列举用来驱动 cron 守护进程的表格的程序。

 

2.启动crontab

service crond start     //启动服务

【小知识】

service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看crontab服务状态

3.安装配置好后,并且启动了,就可以设置打开网页了

 

a.命令 :crontab -e              (打开编辑框输入一下命令)

*/1 * * * * /usr/bin/curl http://www.baidu.com/d.php

如图:

b.命令:

esc 退出编辑;

s 插入文本 

:wq+回车    保存编辑并且返回命令界面

 

4.删除计划任务

 crontab -r

5.特别注意:如果连接后面带有参数需要带有引号,否则不起作用。

如:

*/1 * * * * /usr/bin/curl http://192.168.0.114/dailian/d.php    有效

*/1 * * * * /usr/bin/curl 'http://192.168.0.114/dailian/d.php'   有效

 */1 * * * * /usr/bin/curl http://192.168.0.114/dailian/index.php?g=Portal&m=crontab&a=index    无效

*/1 * * * * /usr/bin/curl 'http://192.168.0.114/dailian/index.php?g=Portal&m=crontab&a=index'   有效

 

【扩展】

crontab -l  查看已经加入的计划任务

*/1 * * * * /usr/bin/curl http://www.baidu.com/d.php    // 每个1分钟运行一次

* 1 * * * /usr/bin/curl http://www.baidu.com/d.php    // 每个1小时运行一次

* * * * * /usr/bin/curl http://www.baidu.com/d.php    // 5个*号的意思是

minute - 从0到59的整数 
hour - 从0到23的整数 
day - 从1到31的整数 (必须是指定月份的有效日期)
month - 从1到12的整数 (或如Jan或Feb简写的月份)
dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)

 

【其他写法】

每天早上6点
-----------------
0 6 * * * echo "Good morning." >> /tmp/test.txt //注意单纯echo,从屏幕上看不到任何输出,因为cron把任何输出都email到root的信箱了。

每两个小时
-----------------
0 */2 * * * echo "Have a break now." >> /tmp/test.txt

晚上11点到早上8点之间每两个小时,早上八点
-----------------
0 23-7/28 * * * echo "Have a good dream:)" >> /tmp/test.txt

每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点
-----------------
0 11 4 * 1-3 command line

1月1日早上4点
-----------------
0 4 1 1 * command line

posted @ 2017-07-21 15:39  IT小码农  阅读(894)  评论(0编辑  收藏  举报