#!/usr/bin/expect
set server [lindex $argv 0];
set folder [lindex $argv 1];
spawn ssh $server
expect "msun@$server's password:"
send "$env(MY_PASSWORD)\r"
send "mkdir -p /home/$folder\r"
send "exit\r"
interact
spawn bash -c "sudo scp ~/sound/*.* msun@$server:/home/$folder"
expect {
"Password:" {
send "$env(MY_PASSWORD)\r"
exp_continue
}
"msun@$server's password:" {
send "$env(MY_PASSWORD)\r"
exp_continue
}
}
sleep 1
exit
In .bash_profile
export MY_PASSWORD = "12345"
File name is sshscp.exp
Usage: ./sshscp.exp serverName folderName