Automating SSH Logins with Expect
You can use TCL/Expect to automate SSH logins to a remote server to execute a command on that server. The following example will SSH into a server and restart apache.
You can use TCL/Expect to automate SSH logins to a remote server to execute a command on that server. The following example will SSH into a server and restart apache.
#!/usr/bin/expect set server "127.0.0.1" set servpass "password" set servuser "root" set command "/etc/init.d/httpd restart" spawn ssh "$servuser@$server" expect "assword: " send "$servpass\r" expect "]#" send "$command\r" expect "]#" send "exit\r"
This is a very simple example, but this script can be expanded to do much more complex tasks.
