Linux定时任务请求一个链接
windows
虽然也有定时任务,不过跟Linux
系统自带的定时任务是有差别的,它需要访客访问时检测而进行的。如果使用Linux
则可以在明确的时间中执行任务,而不需要有人干预,本文将学习一下这方面的东西。
1.登录ssh
,执行以下命令,进入vim
模式,使用i编辑这个crontab
文件,使用:wq
命令保存。
1 | crontab -e |
2.你可以使用以下的任意三种方式来请求一个链接。
Add ONE of the following lines:
1 | 45 * * * * /usr/bin/lynx -source http://example.com/cron.php |
3.例如使用wget请求某个链接,我们可以使用下面的格式。
1 | * * * * * wget -O - http://yoursite.com/tasks.php >/dev/null 2>&1 |
That should work for you. Just have a wget script that loads the page.
Using -O - means that the output of the web request will be sent to STDOUT (standard output)
by adding >/dev/null we instruct standard output to be redirect to a black hole. by adding 2>&1 we instruct STDERR (errors) to also be sent to STDOUT, and thus all output will be sent to a blackhole. (so it will load the website, but never write a file anywhere)
4.前面的*号代表一下时间
minute: 0
of hour: 1
of day of month: * (every day of month)
of month: * (every month)
and weekday: 1-5 (=Monday til Friday)