Remote execution of commands on Linux, Unix, Solaris using expect

#!/usr/local/bin/expect -f
# ./ssh.sh user password IP/Host cmd cmd_arg
set user [lrange $argv 0 0]
set password [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set cmd [lrange $argv 3 3]
set cmd_arg [lrange $argv 4 4]
set timeout -1
spawn ssh $user@$ipaddr $cmd $cmd_arg
match_max 100000
expect “*?assword:*”
send — “$password\r”
send — “\r”
expect eof