1 install expect
sudo apt-get install expect
2 write shell script as the following:
#!/usr/bin/expect -f
# Expect script to supply root/admin password for remote ssh server
# and execute command.
# set Variables
set password "YOUR_PASSWORD"
set ipaddr "REMOTE_HOSTNAME"
set port 22
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh $ipaddr -l root -p 22
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof
3 save this file as edwin.ssh, and add X permission for it
4 use it
./edwin.ssh
1 comment:
Thank you. Was struggling with this for a long time. Was missing the '#!/usr/bin/expect -f' in the begining
Post a Comment