954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

bash expect issues

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

jesseb07
Junior Poster
111 posts since Dec 2006
Reputation Points: 76
Solved Threads: 15
 

did you try using

./shell-script 'ssh [email]user@server.com[/email]' 'password'

?

rast1979
Newbie Poster
3 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

I missed that in my proofreading of my post, yes I intended to say that initially. Here is an example of my script running (input & output):

I type in "./shell-script 'ssh [email]user@sever.com[/email]' 'password'" and hit enter

it outputs "spawn ssh [email]user@server.com[/email]"
then it outputs ssh's output "user@server.com's password:"
and it stays there for a few seconds til ssh times out on the password and it exits.

~J

jesseb07
Junior Poster
111 posts since Dec 2006
Reputation Points: 76
Solved Threads: 15
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You