This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem on expect command

 
rama ilango
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • 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?.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic