About Me

- A little contribution to the linux newbies.

Friday, October 9, 2009

Expect - Sample Scripts

Following scripts will "ssh" into the remote machine and will "execute the command" that you pass to be executed on the remote system.

#!/usr/bin/expect -f
# USAGE:
#----------------------------------------------------
# ./ssh-expect.exp 'command to be executed on remote machine'
#----------------------------------------------------
# set Variables
set password [lrange $argv 0 0]
set remote_ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 2]
set arg1 [lrange $argv 3 3]
set timeout -1
spawn ssh root@$remote_ipaddr $scriptname $arg1
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password to the remote machine
send -- "$password\r"
send -- "\r"
#terminate the connection
expect eof

No comments:

Post a Comment