Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP NEEDED WITH EXPECT & CRONTAB 1

Status
Not open for further replies.

riteshch

Programmer
Jul 27, 2003
8
US
I have a expect script which does rlogin to a remote box and runs a script there on remote box.. when i run it from command prompt it runs fine... but when i run it from crontab it does not... it gets stuck when expecting a password..

can anyone help me on this please ?

=== SCRIPT =====

#!/usr/bin/expect
eval spawn rlogin b12345 -l testuser
expect "Password:"
send "test123\r"
send "/home/testuser/runScripts\r"
send "exit\r"
interact


==== crontab entry ===

sunil@homer eastLoad]$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.21168 installed on Sun Jul 27 15:09:39 2003)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
#!/usr/bin/expect
10 15 * * * /home/sunil/eastLoad/scriptname

i tried to run with full path also in crontab (/usr/bin/expect <script name> and /user/bin/expect -f <script name> ) but of no use...

This is what I am getting in mail

Subject: Cron <sunil@homer> /usr/bin/expect -f /home/sunil/eastLoad/runSigill
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/sunil>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=sunil>

spawn rlogin b12345 -l testuser
Password:


 
I'm not sure off the top of my head but I suspect that it has something to do with the fact that when the script is run from cron it has no STDIN for Expect to hook up to to simulate the password keystrokes.

I'll try and remember to look it up in my Exploring Expect book tonight.

BTW - why do you have #!/usr/bin/expect in your crontab?
 
I added &quot;#!/usr/bin/expect&quot; in crontab as part of hit and trail.. but with and without this result is same...

I also suspect stdin issue.. now i am even calling a wrapper scipt first from cron tab which calls my script..

in wrapper script i am setting TERM e.t.c but still result is same
 
where's marsd when you need one! [wink]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Any reason why you're using rlogin instead of rsh? If you switch to rsh, try using the -n switch, which makes it treat stdin and stdout differently.

Annihilannic.
 
Your problem in is the expect script.

You need to end with &quot;expect eof&quot; vs &quot;interact&quot;.

Interact is used when the expect script is run from the command line. Use expect eof when running from a cron.

Cheers,
texmexdude
 
Well done texmexdude, I've been trying to solve this one for days and even installed it on my test server to work through it, probably spent 2hrs surfin! for an answer and di'int find one, and it was that simple!!

You get a STAR!!

Now I'm hooked and I'll have to buy the book (or shall I just delete Expect from my test server and call it quits?)

I hope that sort's it for you riteshch?
my (your login script on) test server logs in ok from cron having replaced interact with expect eof

Oh! and I've been using &quot;exp_internal 1&quot; in my Expect script to see debug info (worth looking at that too).

Laurie.
 
Hi
I have faced the same problem. But when you put 'expect eof', a timeout occurs and the scripts just terminates. This doesn't happen with interact. Timeout cannot be -1 because if a remote server is hung, it will never timeout.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top