<?php /* Notify the user if the server terminates the connection */ function my_ssh_disconnect($reason, $message, $language) { printf("Server disconnected with reason code [%d] and message: %s\n", $reason, $message); } $methods = array( 'kex' => 'diffie-hellman-group1-sha1', 'client_to_server' => array( 'crypt' => '3des-cbc', 'comp' => 'none'), 'server_to_client' => array( 'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc', 'comp' => 'none')); $callbacks = array('disconnect' => 'my_ssh_disconnect'); $connection = ssh2_connect('10.10.10.1', 22, $methods, $callbacks); if (!$connection) die('Connection failed'); if (ssh2_auth_password($connection, 'login', 'password')) { $stream = ssh2_exec($connection, "dmesg | grep 'wifi0: transmit timed out'"); stream_set_blocking($stream, true); $data = ""; while ($buf = fread($stream, 4096)) { $data .= $buf; } fclose($stream); if ($data!="") ssh2_exec($connection, "reboot");; } else { die('Authentication Failed...'); } ?>
Источник