javascript – shell script not being invoked via php and completion status running shell script in php-ThrowExceptions

Exception or error:

I am using php to control(start/stop) my servers. Inside php I am using shell_exec, which runs shell script and start/stop the server. Following is the code for button and further action upon button click.

<table><tr><td>Server1</td><td><form method="post"><input type="submit" class="btn btn-primary btn-xs" name ="start_as" value="start"/>
</form>
<?php
function startAS()
{
shell_exec("/$path/startASServer.sh");
}
if(array_key_exists('start_as',$_POST)){
   startAS();
}
?>
</td></tr></table>

and below my sh file:

ssh user@ip "nohup /$path/startASServer.sh > /dev/null 2>&1 &"
SERVER=ip1 PORT=port1
while !(: < /dev/tcp/$SERVER/$PORT) 2>/dev/null
do
    echo "* Waiting for  Server to Start *"
done
echo "Server is Started"

The problem is when I click on “start” button, the browser hangs and I can not see shell script being run on server, request expert guidance here. Also, if there is anyway wherein I can show two updates in popup window showing task started and task completed.

Thanks

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *