对 shell 语法不熟,有个这样的需求,用 crontab 每天定时执行一次 xxx.sh 。xxx.sh 里面的逻辑是这样的:不断 curl 请求 http://xxx.com/xxx.php ,xxx.php 会输出 1111 和 0000 ,当 xxx.php 输出 1111 时,继续请求 xxx.php ,直到输出 0000 ,xxx.sh 执行结束,请问下这个 xxx.sh 该怎么写?谢谢
1
xhat Apr 2, 2015
或许你是想要:
crontab里面执行 /usr/bin/php *.php |
3
47jm9ozp Apr 2, 2015 这个不是返回值……
RESULT=1111 while [[ $RESULT != "0000" ]]; do RESULT=$(curl xxxxxxxxx) sleep 1 done |
4
jyz19880823 Apr 2, 2015
result=`curl http://xxx.com/xx.php -s`
|
5
chinawrj Apr 2, 2015
可以输出到stdout, wget是"-",你看一下help。curl是啥。。
|
6
clanned Apr 2, 2015 这个是你要的
https://gist.github.com/xdtianyu/aa339f6003604ef6a72f xxx.sh文件 ---- #/bin/bash URL="http://192.168.5.100/xxx.php" check() { RESULT=$(curl -s http://192.168.5.100/xxx.php) echo $RESULT if [ "$RESULT" -eq "1111" ] ; then echo "again" sleep 1 check elif [ "$RESULT" -eq "0000" ] ; then echo "exit" exit 0 else echo "error" fi } check ---- xxx.php文件模拟 ---- <?php if (rand()%5==0) { echo "1111"; } else { echo "0000"; } ?> |
8
cevincheung Apr 2, 2015 如果一定要用脚本的话不如用python了。- -#
|
9
wate Apr 3, 2015
@cevincheung 所言甚是
|