Calling shell script from PHP is not working as expected -


i trying open remote machine browser machine. have setup password less connection ( considering fact both systems in same n/w , trusted).

i able run below script launch browser, takes 3 arguments

a). username
b). ip address of remote machine
c). url open in firefox

if run script in bash shell, able open browser without issues. if call inside php, not able launch browser on remote machine...it shows debug prints fails open browser. pointers helpful.

below shell script open browser on remote machine.

#!/bin/bash if test $# != 3;      echo "          $0          command line script used launch, browser remotely. need pass 3 arguments script.          need pass 3 argumemts script,          example , \$> sh $0 \"<usernameofremotesystem>\"  \"<remotesystemip>\"  \"<webpageaddress>\"           \$> sh $0 \"uname\" \"172.17.64.94\"  \"mail.google.com\" \n";          exit 1 fi  echo "<br><br>\nreceived parameters,\n\tusername\t-> |$1|\n\tipaddress\t-> |$2|\n\tweburl\t\t-> |$3|\n\n<br>"; echo "<br>checking if connection |$2| username |$1| password less???<br><br>"; sleep 2  echo "<br>grep -wc $1 /home/user/.ssh/authorized_keys<br>"; count=`grep -wc $1 /home/user/.ssh/authorized_keys`; echo "<br>got process count=|$count|<br>"  sleep 2  if [ "$count" != 1 ];     echo "        looks password less connection |$2| not configured server username |$1|..        please congfigure same , run script again...\n"; fi  echo "successfully connected, launching browser on |$2| |$3|\n"; ssh $1@$2 "nohup sh openbrowser.sh $3" & pid=$$; echo "pid |$pid|\n"; sleep 2; echo "<br>process output looks this"; ps aux | grep $pid | grep -v grep echo "<br>"; echo "after sleep"; kill -9 $pid && echo "after kill pid=$pid, passed ssh $1@$2 \"nohup sh openbrowser.sh $3\" &"; 

below php script using call shell script.

<?php     $c_url=$_post['url'];     $c_name=$_post['uname'];     $c_ip=$_post['ipaddress'];      $output = system("/bin/sh /home/user/launchbrowser_remote.sh $uname $ipaddr $c_url");     echo "$output"; ?> 

looks getting wrong pid inside shell script , killing caller script rather launching ssh remote ..... btw have tried both exec , shell_exec no luck.

any pointer helpful

thanks

make sure user running php file (web server user if being called in context) set password-less authentication well.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -