first you need to install expect:
sudo apt-get install expectthen create a new expect script file:
nano -w expect_ssh.expand give it this code:
#!/usr/bin/expect
eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no myuser@myremoteserver.example.com
# i know that the remote shell uses $ at the end of their prompt
set prompt "\\$"
expect "*?assword:*"
send -- "mySecretPassword\r"
interact -o -nobuffer -re $prompt return
send -- "rm -f remote_file_to_be_deleted.txt\r"
interact -o -nobuffer -re $prompt return
make the script executable:
chmod +x expect_ssh.exprun the script like this:
./expect_ssh.exp
thanks to:
http://bash.cyberciti.biz/security/expect-ssh-login-script/
http://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command
man expect (huge man page, lots to read)
No comments:
Post a Comment