• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem on expect command

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic