It is currently Fri Feb 24, 2017 2:07 am

Pass string to program input prompt

All times are UTC - 6 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Mar 27, 2009 11:10 am   

Joined: Fri Mar 27, 2009 10:55 am
Posts: 1
Location: Wisconsin, USA
Hello, everyone. I have a problem, and I've been searching for an answer all day. Hopefully someone here can help me.

I'm writing a script that will ping every IP address on the subnet, and for each computer that responds, it will ssh in with a username (os) and a password (itnsA0h9), perform some commands, and move on to the next host.

While the username can be specified as part of the ssh command, the password can not, and I can not figure out how to pass the password from my script to the input prompt of the ssh program.

The relevant code:
echo "Attempting to log in to ${target} (MAC: ${mac})"
ssh os2@${target}

So far I've tried:
ssh os2@${target} < /home/justus/sshpass.txt    #this file contains the password

echo "itnsA0h9" | ssh os2@${target}

ssh os2@${target}
pause 3
echo "itnsAoh9"

I've Googled my problem, and while there are solutions listed, they all suggest adding a authentication key to each machine so that ssh does not ask for a password at all. I do not want to do this, as that would mean adding a key for each machine in my subnet.

I've only my second day scripting with BASH, so I apologize if I'm missing something obvious. Thanks!

 Profile WWW  
 PostPosted: Sat Mar 28, 2009 8:53 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 635
Are you sur SSH is the best way to perform what you want to do on your server?
Have a look here to connect to SSH server, "without" password, using rsa identification.

 PostPosted: Sun Mar 29, 2009 5:25 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
There is another solution, there is a utility (atleast for unix) that does this. It's named "expect".
I'm not especially good at it thou so you'll need to google it.
It might be possible to use xargs also.

Best regards
Fredrik Eriksson

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 6 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group