--- alx-src/branches/alx-web-060/include/common-functions.php 2011/05/09 21:58:32 2021
+++ alx-src/branches/alx-web-060/include/common-functions.php 2011/05/09 22:13:37 2022
@@ -1,8 +1,9 @@
include("config.inc.php");
- function exec_on_client($serial, $ip, $cmd, $verbose=0)
+ function exec_on_client($serial, $ip, $cmd, $failure=1, $verbose=0)
{
+ global $pingcmd;
global $sshcmd;
$pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$serial.'');
@@ -13,24 +14,31 @@
fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
fclose($hostfile);
- # exec the cmd
- echo "sshcmd: '".$sshcmd."'
";
-
- exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $outarr, $err);
- if ($verbose == 1)
+ # check if the client is online
+ passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1', $retval);
+ if ($retval == 0)
{
- echo "err: '".$err."'
";
- foreach( $outarr as $i )
+ if ($verbose == 1) echo "sshcmd: '".$sshcmd."'
";
+
+ # exec the cmd
+ exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $cmdout, $err);
+ if ($verbose == 1)
{
- echo "outarr: '".$i."'
";
+ echo "err: '".$err."'
";
+ foreach( $cmdout as $i )
+ {
+ echo "cmdout: '".$i."'
";
+ }
}
- }
- if($err != 0) echo '';
- else if ($verbose == 1) echo '';
-
- return $outarr;
+ if($err != 0) if ($failure == 1) echo '';
+ else if ($verbose == 1) echo '';
+ }
+ else if ($failure == 1) echo '';
}
+
+ # return the output of $cmd
+ return $cmdout;
}
?>