Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help! how to Expect from System command

Status
Not open for further replies.

vinhnguyen18

Technical User
Aug 29, 2009
4
US
Hi,

What I'm trying to do:
Manually from bash shell, if I execute this command:
ssh $ip -l $username -s netconf < 500M_file
This redirects entire content of 500M_file to my ssh channel. The server listening on this channel, will get the content, do some stuff and return some string.

When automating this using "spawn ssh...", things are working fine, and I can use "expect 'Password:'" to enter password. However this method this not work well for me because once in "spawn ssh..." I will have to open the 500M_file, read it, then do "send...". Since the file is so huge, it hogs up all my memory.

Therefor, I'm thinking of just using "system" command as follows:
system "ssh $ip -l $username -s netconf < 500M_file"
But when doing this command, I get a prompt for password. Eventhough I do a "send 'password\r'", it just does not responds and hangs there. I'm guessing that I'm not sending to the correct I/O.

I would appreciate any advise/help with this.
 
After digging around some Expect book, I found the solution to this:

spawn /bin/sh -c "ssh $ip -l $username -s netconf < somefile.xml"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top