1834771 Members
2976 Online
110070 Solutions
New Discussion

help with expect script

 
sparky_2
Frequent Advisor

help with expect script

Hi all. I am using expect for the first time to rlogin into a set of servers. This is my basic script -
#!/usr/local/bin/expect -f
set host [ exec cat hostlist ]
set send_slow {1 .1}
set pass
send "rlogin $host -l "
expect "Password: "
send "$pass\r"
send "exit"

When I run this in debug mode, I get the following error:
expect: does "" (spawn_id 0) match glob pattern "Password: "? no

Any assistance would be greatly appreciated! Thanks.
4 REPLIES 4
Chris Wilshaw
Honored Contributor

Re: help with expect script

You need to use {} in place of the "" following the expect line, and I think you need to add a newline (\n) to the end of the sends too.

Try this;

#!/usr/local/bin/expect -f
set host [ exec cat hostlist ]
set send_slow {1 .1}
set pass
send "rlogin $host -l \n"
expect {*word:}
send "$pass\n"
send "exit\n"
sparky_2
Frequent Advisor

Re: help with expect script

Thanks Chris, but I'm afraid this made no difference.

I have now replaced the line
expect "Password: "
with
expect ""
and the call now seems to suceed (ie, it reports a match). But this has still not acheived what I intend for the script, so further assistance required!

I will explain what I am trying to achieve. I have a NIS+ account that has been reset. The username has a .rhosts file on all systems so that it can perform an rcp without the password being required. However, since the account was reset, you need to rlogin with the password initially before this can happen (reports account disabled until this is done).

Is using expect the best way to achieve this? Is there further debugging (other than the -d in the shell path) that I can implement to check whether the script is succeeding?
Raj D.
Honored Contributor

Re: help with expect script

Hi Sparky ,

Chek this link it may help you further , making the script with expect.

http://www.cpqlinux.com/expect.html

And good example included.

Cheers,
" If u think u can , If u think u cannot , - You are always Right . "
sparky_2
Frequent Advisor

Re: help with expect script

After lots of experimentation, I changed the line
send "rlogin $host -l "
to
spawn rlogin $host -l
and re-implemented the
expect "Password:"
line.
This has worked!

Being an expect newbie, I don't know why. If anyone can explain this behaviour to me, that would be great.

Thanks for the responses so far.