#!/usr/bin/expect -f
# Expect script to supply username, password for remote ssh server 
# and execute command.
# This script needs three argument to(s) connect to remote server:
# password = Password of remote UNIX server, for root user.
# ipaddr = IP Addreess of remote UNIX server, no hostname
# scriptname = Path to remote script which will execute on remote server
# For example:
#  ./sshlogin.exp username password 192.168.1.11 who 
set userName [lrange $argv 0 0] 
set password [lrange $argv 1 1] 
set ipaddr [lrange $argv 2 2]   
set scriptname [lrange $argv 3 3] 
set arg1 [lrange $argv 4 4] 
set arg2 [lrange $argv 5 5] 
set arg3 [lrange $argv 6 6] 
set arg4 [lrange $argv 7 7] 
set timeout -1   
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh -l $userName $ipaddr $scriptname $arg1 $arg2 $arg3 $arg4
match_max 100000
expect "*?assword:*"
send -- "$password\r"
send -- "\r"
expect eof