This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes problem on expect command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "problem on expect command" Watch "problem on expect command" New topic
Author

problem on expect command

rama ilango
Greenhorn

Joined: Dec 11, 2008
Posts: 24
hi

I am using expect command to connect remote host.Through this command i send password and yes/no.
the command is,



This command is working perfectly some times.But some times asking password.
how to solve it?.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11464
    
  94

Please put formatted code inside [code] and [/code] tags so it can be easily read and analyzed. I spent more time trying to work out whether your braces were correct and then reformatting your post than I should have, resulting in having less time to actually look at your problem.

A couple of quick thoughts -

You are expecting "aassword" - is this correct? The word Password normally only has a single "a", so I would not have expected your script to ever work.

I think that the problem is likely to be with the fact that you have nothing after the sending of the password - you just allow the expect command to return. So sometimes the timing will be right and you will have an instantaneous login on the remote box that will be immediately dropped, and sometimes expect will complete before you see the output.

So 2 possibilities:

Try putting an "interact" as the line after the "send password\r" - that will allow you to see what happens next, and allow you to use the connection you just made.

-or-

Try putting 'expect "Last login"' (or whatever text your login should provide) following the send so you can confirm that you are getting it.

- Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11464
    
  94

As an aside, it is really bad practice to have usernames and passwords in an executable script. You might want to consider putting them into a file that is read-only by you alone:

Then change your script to work with this as well:


- Andrew
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11464
    
  94

And, a step further, putting both username and psasword into the same file, separated by a space:


It should be possible to short circuit those assignments by using the lassign command, but it is not working on my box at the moment, and I really should be doing real work. Meh.

- Andrew
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11464
    
  94

One more comment, while I am thinking about this: if the expect scriptlet is the only work being performed in your overall script, you might want to consider pulling it out into an expect script of its own. This will help you in debugging, and (if you have a decent editor) you should get proper color coding.

That is, if I put your script above into a bash script, everything between the single quotes appears as a single color. Whereas if I put it in a file named rama.exp then vim is intelligent enough to work out that this is an expect script and deals with it accordingly. So the script now becomes:


-Andrew
rama ilango
Greenhorn

Joined: Dec 11, 2008
Posts: 24
The above script is working perfectly.

But using spwan ssh root@192.168.xx.xx ls in that script, it gives the output is

spwan ssh root@192.168.xx.xx ls
getip.sh
install.log
install.log.syslog
ipmac.sh

The output is correct.But my requirement is how to get the output without the line "spwan ssh root@192.168.xx.xx ls" in the output.that is how to display only
getip.sh
install.log
install.log.syslog
ipmac.sh
 
GeeCON Prague 2014
 
subject: problem on expect command