note 125227 added to function.ssh2-shell
| From: | nogueiraconsultoria at gmail dot com | Date: | Wed, 29 Jul 2020 13:25:17 +0000 |
| Subject: | note 125227 added to function.ssh2-shell | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214909@lists.php.net to get a copy of this message | ||
I get it a work script for multiple commands. This script return output of each command on array,
indexed by the "command".
Att: ssh2_cmd() dont work for multiple commands, thus ssh2_shell(). Attencion for de EOL on witch
type of SO. I used "\n" at the end of witch command, but maybe other options like
"<br>, ; , etc);
$connection = ssh2_connect($input_host_ip, 22);
if (false === $connection) {
error_log("ERROR função SSH_UMTELECOM: Connection
failed!\n",3,$log_file);
exit();
}else{
if($debugar){error_log("SSH_UMTELECOM: Connection success to
$input_host_ip!\n",3,$log_file);}
$auth = @ssh2_auth_password($connection, $user, $pass);
if (false === $auth) {
error_log("ERROR função SSH_UMTELECOM: Authentication failed on
$input_host_ip (user: $user)!\n",3,$log_file);
exit();
}else{
if($debugar){error_log("SSH_UMTELECOM: Authentication success to
$input_host_ip!\n",3,$log_file);}
error_log("Iniciando Stream: $connection\n",3,$log_file);
$output_array = array();
$shell = ssh2_shell($connection, 'vt100');
foreach($input_cmd as $cmd){
if($debugar){error_log("shell: $cmd\n",3,$log_file);}
$output_stream = ""; # Limpa variável para cada
interação
fwrite($shell, "$cmd\n"); # Não esquecer o
"\n" ao término de cada comando
#stream_set_blocking($shell, true); # Não funciona, aguarda
infinitamente
sleep(2); # 2 segundos para redes com alta latência
while($output_streams = fgets($shell)){
$output_stream .= $output_streams;
flush();# Limpa o conteúdo para a próxima
interação
}
$output_array[] = $output_stream; # Reune cada retorno em seu
respectivo comando
}
fclose($shell); # Gracius logout from shell
}# Fim if false === $auth
}# Fim if false === $conenection
----
Server IP: 45.112.84.4
Probable Submitter: 177.234.144.170 (proxied: 177.36.14.109)
----
Manual Page -- http://php.net/manual/en/function.ssh2-shell.php
Edit -- https://master.php.net/note/edit/125227
Del: integrated -- https://master.php.net/note/delete/125227/integrated
Del: useless -- https://master.php.net/note/delete/125227/useless
Del: bad code -- https://master.php.net/note/delete/125227/bad+code
Del: spam -- https://master.php.net/note/delete/125227/spam
Del: non-english -- https://master.php.net/note/delete/125227/non-english
Del: in docs -- https://master.php.net/note/delete/125227/in+docs
Del: other reasons-- https://master.php.net/note/delete/125227
Reject -- https://master.php.net/note/reject/125227
Search -- https://master.php.net/manage/user-notes.php