bash commands using php
Posted: Wed Apr 21, 2010 2:44 pm
i m trying to run multiple bash commands using php...
something like this " echo '[start]' ; cd /dir; ls; echo '[end]' "
now the problem is i want to run this bunch of commands on different hosts.
the {start] and [end] strings are mainly for gettin the output of bash shell.
the problem is for different hosts i m getting different output i.e. not the correct list of files in that dir
to print out the output i m using this method
start_time = time()
$max_time = 1;
while(((time()-$start_time) < $max_time)) {
$line = fgets($shell);
if(preg_match('/\[start/',$line)) {
$start = true;
}elseif(preg_match('/\[end\]/',$line)) {
return $output;
}elseif($start){
$output = $output.$line;
}
}
i know this is not the best method of gettin the output....can you please suggest other ways?...or help me modify this method?
something like this " echo '[start]' ; cd /dir; ls; echo '[end]' "
now the problem is i want to run this bunch of commands on different hosts.
the {start] and [end] strings are mainly for gettin the output of bash shell.
the problem is for different hosts i m getting different output i.e. not the correct list of files in that dir
to print out the output i m using this method
start_time = time()
$max_time = 1;
while(((time()-$start_time) < $max_time)) {
$line = fgets($shell);
if(preg_match('/\[start/',$line)) {
$start = true;
}elseif(preg_match('/\[end\]/',$line)) {
return $output;
}elseif($start){
$output = $output.$line;
}
}
i know this is not the best method of gettin the output....can you please suggest other ways?...or help me modify this method?