The best place to ask programming/development questions, imo. UPDATE: stackoverflow is the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but a great reference for finding answers.

My Music (Nickleus)


automatically connect to remote server by ssh then perform remote commands using expect script

first you need to install expect:
sudo apt-get install expect
then create a new expect script file:
nano -w expect_ssh.exp
and give it this code:
eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no
# 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.exp
run the script like this:

thanks to:
man expect (huge man page, lots to read)

No comments:

Post a Comment