简体   繁体   中英

PHP shell_exec does not work for some commands?

If I do the following command, I get an 'hey' output:

echo shell_exec("echo 'hey'");

But If I do the following command, it will not kill any screen :

echo shell_exec("killall screen");

Or if I do

echo shell_exec("sh /var/www/html/run.sh");

It will not run that file at all (that file does the screen killing aswell)

And If I even get that file with get contents, it successfully reads the content in it.

If it can execute echo so whats wrong?

To run such powerful commands, I had to use this library as stated in this question . This allows me to login into the SSH with root access and execute any command!

function ssh_script($script, $ip, $user, $pass) {
            $ssh = new Net_SSH2($ip);
    if (!$ssh->login($user, $pass)) {
        exit('Login Failed');
    }

    if ($ssh !== false) {
        echo $ssh->exec("sh " . $script);
    }
    else {
        echo "fail";
    }
}

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