hello, I wrote an expect script to automate ssh commands, and it was working, but for some reason it's not anymore. Just to make sure I didn't do any weird changes that I didn't notice, I tried several of the dozens of such scripts that are online, and for some reason, none of them work. Here's the script I wrote, that did work at one time, but maybe there are some suggestions, I'm not the best at shell scripting.
I wrote this to work with ssh as well as rsync, so $1 is the command you want it to run, with $2 being the password, example of calling this would be: "./shell-script 'user@server.com ls' 'password'"
I am using ubuntu linux.
#!/bin/bash
#!/usr/bin/expect
expect -c "
spawn $1
expect {
password: { send $2; exp_continue }
}
exit
"
exit 0
I should add, that this script will call the command ($1), but it will hang when it comes to entering the password. I've tried several different strings for it to expect, none of them work. The format ssh outputs for asking the password is 'user@server.com's password:' so I've tried 'password:', 'word:' and ':'
thanks
~J