###Warning I have no idea when I wrote this and when I last used expect
#!/usr/bin/expect
set timeout 20
set host [lindex $argv 0]
set password "secret"
set prompt "$ "
proc dostuff {} {
send -- "put seamus.sh\r"
return
}
#spawn scp -q seamus.sh ${host}:/tmp/shell_script.sh
spawn sftp -q ${host}
while (1) {
expect {
;# -- This is the prompt when you first use
;# -- ssh that says "Are you sure you want to continue ..."
"no)? " {
send -- "yes\r"
}
;# -- the prompt for password
"Password: " {
send -- "$password\r"
}
;# -- and finally we got a shell prompt
"$prompt" {
dostuff
break
}
}
}
;# -- exit
expect "$prompt"
send -- "exit\r"
expect eof
#######################################################################
#!/usr/bin/expect
set timeout 20
set password [lindex $argv 0]
spawn sudo su \-
expect "seamusmurray:"
send "$password\r";