1、首先编写shell脚本 如下:
#!/bin/bash
step=2 #间隔的秒数,不能大于60
for (( i = 0; i < 60; i=(i+step) )); do
$(curl 'localhost:8080')
sleep $step
done
exit 0
step 为60的约数时 在crontab -e编辑的时候如下:
* /1 * * * * /var/www/html/timer.sh
/var/www/html/timer.sh 为运行脚本
step 不是60的约数时(例如7) 可以实现如下:
把i<60 改为:i<420(最小公倍数)
在crontab -e编辑的时候如下:
* /7 * * * * /var/www/html/timer.sh
/var/www/html/timer.sh 为运行脚本