简体   繁体   中英

Getting response from unix commands executed via PHP

I would like to list the Cron tasks for a given user in the browser. I am using the following, which works fine via SSH:

crontab -u username -l

Which outputs something like:

*/2 * * * * cd /home/username/public_html/cron; php -q -c ./ cron_4.php
*/2 * * * * cd /home/username/public_html/cron; php -q -c ./ cron_3.php
*/2 * * * * cd /home/username/public_html/cron; php -q -c ./ cron_2.php
0 0 * * * cd /home/username/public_html/cron; php -q -c ./ cron_1.php

However, when I try to do it via PHP...

$return = array();
$command = "crontab -u username -l";
passthru($command, $return);
echo "<pre>";
var_dump($return);
echo "</pre>";

I only get...

int(1)

Whereas I was expecting an array containing each of the above lines.

How can I achieve the expected result via PHP?

I ended up using exec()

$r=[];
exec($command,$r);

The actual problem was something to do with permissions and is irrelevant to the question as I stated it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM