PHP shell_exec命令输出脚本提示成功/失败并重定向到索引页


How to PHP shell_exec a command output script allert success/failed and redirect to index page

我是一个PHP新手。正在运行PHP脚本shell_exec,调用命令scp.sh效果很好。现在我只想要一个显示成功/失败消息的提示/警报。然后重定向到index。php。

这是我的phptransfer.php

    $old_path = getcwd();        
    chdir('/root/');        
    $output = shell_exec('sudo sh scp.sh');        
    chdir($old_path);        

Bash文件scp.sh content

#!/bin/bash                  
scp -r /usr/mail/* user@host:/root/mail/        

请帮帮我。

#!/bin/bash
if scp -r /usr/mail/* user@host:/root/mail/ ; then
    echo "Command succeeded"
else
    echo "Command failed"
fi

这就是在bash中根据命令成功或失败看到成功/失败消息的方式。如果你想要一个php消息,请进入php section