-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


The Friday 2008-01-25 at 10:01 -0500, james wright wrote:

On Friday 25 January 2008 08:37:24 am Ken Schneider wrote:

Try using expect to do what you want. I used expect when connecting to
Cisco routers to do configuration changes with the password embedde3d in
the expect script.

Ah, expect! Got the name wrong.

You should obviously read the man page, but if you want to start having fun
right away, paste the below script into a file, change the name, host, and
password to fit your environment and run it with:

expect FileYouSaved

Here is the script:

#!/usr/bin/expect
spawn ssh -l UserNameHere 192.168.1.111
expect Password:
send "PassWord\n"
interact


Note:  You need the \n at the end of your password.


Good! Seems easy... but doesn't quite work. I have:

#!/usr/bin/expect
spawn ssh -l 1234 router
#expect [EMAIL PROTECTED]'s password:
expect Password:
send "password\n"
interact


but I get:

[EMAIL PROTECTED]:~> router_ssh
spawn ssh -l 1234 router
[EMAIL PROTECTED]'s password:


and it doesn't enter. I modify the script:

#!/usr/bin/expect
spawn ssh -l 1234 router
expect [EMAIL PROTECTED]'s password:
send "password\n"
interact


and now I get:

[EMAIL PROTECTED]'s password: invalid command name "password:"
    while executing
"password:"
    invoked from within
"expect [EMAIL PROTECTED]'s password: "
    (file "/home/cer/bin/router_ssh" line 3)


I escape the ' with \ and still I get:


[EMAIL PROTECTED]:~> router_ssh
spawn ssh -l 1234 router
[EMAIL PROTECTED]'s password: invalid command name "password:"
    while executing
"password:"
    invoked from within
"expect [EMAIL PROTECTED]'s password: "
    (file "/home/cer/bin/router_ssh" line 3)


Why is it trying to execute "password"? That's absurd.

Ah! I got it!

expect "[EMAIL PROTECTED]'s password: "



Well... now I want one step more:


#!/usr/bin/expect
spawn ssh -l 1234 router
expect "[EMAIL PROTECTED]'s password: "
#expect Password:
send "****\n"
send "ping -c 50000 192.168.1.12"
interact



[EMAIL PROTECTED]:~> router_ssh
spawn ssh -l 1234 router
[EMAIL PROTECTED]'s password:
 ->


The ping command is not sent... Ah, got it!

expect "[EMAIL PROTECTED]'s password: "
send "****\n"
expect " ->"
send "ping -c 50000 192.168.1.12\n"
interact



  THANK YOU!   :-)))


(I need the router to send pings to my PC, or this computer stops working - - that's another story, there is a bugzilla about it)


- -- Cheers,
       Carlos E. R.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)

iD8DBQFHmg8ntTMYHG2NR9URAk/sAKCAY8ieG/08uH8HeItcMjsih1NN6gCfRial
JltnbqyJ9o9SUc3iyeLLZO8=
=eKVD
-----END PGP SIGNATURE-----
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to