2014-08-31 97 views
0

我一直在努力shell_exec PHP函数和在Linux命令2天。 要长话短说,这个工程:在shell_exec和at命令中使用wget?

shell_exec('/usr/bin/at 09:32 <<EOF 
     touch /var/www/website/hello.txt 
EOF' 
); 

这并不:

shell_exec('/usr/bin/at 09:32 <<EOF 
     wget -O - -q -t 1 "http://192.168.56.101/website/test.php?param=hello" >/dev/null 2>&1 
EOF' 

); 

为什么?

(注:上面的代码不工作在控制台)提前

感谢。

+1

使用['file_get_contents'(http://php.net/manual/en/function.file-get-contents.php)代替wget的。而cron而不是'at'。 'shell_exec'应该被认为是有害的,并且在一般情况下是最后的手段。 – OmnipotentEntity 2014-08-31 08:27:05

+0

工作是否在'at'结束? (http://serverfault.com/questions/174678/how-do-i-print-contents-of-at-jobs) – GhostGambler 2014-08-31 08:30:55

+0

'system_exec'调用的返回值是什么? – GhostGambler 2014-08-31 08:31:12

回答

0

好吧,我终于明白了!

对于那些对pb感兴趣的人来说,wget命令也需要使用完整路径(即:/ usr/bin/wget)来调用。 误导我的是touch命令不需要它。这很奇怪,但无论如何,这里的工作代码:

shell_exec('/usr/bin/at 09:32 <<EOF 
     /usr/bin/wget -O - -q -t 1 "http://192.168.56.101/website/test.php?param=hello" >/dev/null 2>&1 
EOF' 
); 
+0

这是因为触摸是一个shel l内建。 – OmnipotentEntity 2014-08-31 16:52:07

+0

@OmnipotentEntity不,它不是。 – Rapptz 2014-08-31 19:38:13

+0

你是对的!抱歉 – OmnipotentEntity 2014-08-31 20:06:23