aspose file tools*
The moose likes Linux / UNIX and the fly likes problem in running a expect script from crontab Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "problem in running a expect script from crontab" Watch "problem in running a expect script from crontab" New topic
Author

problem in running a expect script from crontab

Ritesh Ritesh
Greenhorn

Joined: Jul 27, 2003
Posts: 3
Hi,
I got your reference from a website while looking for a solution of a problem.
here is the problem:
I have a expect scrips which does rlogin and then runs a script there.
on sun solaris box "a12345", i have a scripts

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

It will rlogin to box "b12345" and will run script runScript under /home/testuser directory.
When I run this script on command prompt, it runs fine. But if I try to run this script it is is not working. I believe since crontab sets the shell to csh first, that why am not able to run thid script.

Can you give me some solution.
Pls help!
thanks
Ritesh
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11484
    
  94

Hi Ritesh
You could try telling cron to run expect with your file as the parameter. So something like:
<code> * 1 * * * /usr/bin/expect -f <myExcpectScript.exp></code>
But even with that, you will still have problems with the last line of your script, where you issue the command "interact". There is no user to interact with this script when running from a cron job.
Regards, Andrew
[ July 27, 2003: Message edited by: Andrew Monkhouse ]

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Ritesh Ritesh
Greenhorn

Joined: Jul 27, 2003
Posts: 3
I tried using /usr/bin/expect -f <filename> in crontab.. but its not working..
its gets stuck when expecting password...
though its working from command prompt
as you said Andrew, its because of "interact"... any solution for this problem ??

-Ritesh
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11484
    
  94

Hi Ritesh
When you run a job using cron, you have a very limited environment, and there are many environmental variables that are either not set, or set differently, to an interactive prompt.
One of the environmental variables that is missing is the TERM variable, detaining what sort of terminal you are running from. This is only to be expected - if you are running from a cron job, you do not have a physical terminal attached (there is no keyboard or screen for the cron job).
This is probably what is causing you problems. From my manual for rlogin:
Try getting a command prompt, and type:<code><pre>
unset TERM
rlogin b12345</pre></code>
Does this look different to what you expect? You are probably getting some notification that TERM is not set.
  • You may be asked what the TERM should be. In which case, just modify your script to answer that question
  • Or the rlogin may be exiting since it doesnt have the TERM set. In which case you will have to set the TERM variable in your crontab (<code>man 5 crontab</code>) or you will have to set the TERM variable in the expect script, or you will have to wrap the expect script in a shell script that sets the TERM variable.

  • As for the "interact" statement - why do you need it? It is not needed in the script you provided - try removing it and running the script from a shell prompt again - you should not see any difference. If you don't need it, remove it.
    Regards, Andrew
    Ritesh Ritesh
    Greenhorn

    Joined: Jul 27, 2003
    Posts: 3
    thanks Andrwe ..
    now am setting TERM in cron tab before calling the script but of no use..
    i wrote a wrapper script which calls that script.. in wrapper script am setting TERM variable and exporting and then am calling that wrapper script from crontab... but still result is same....
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11484
        
      94

    Hi Ritesh
    You should be getting an email each day showing you the output of the script as it runs. This probably has clues as to what is wrong. Can you post it?
    Regards, Andrew
     
    wood burning stoves
     
    subject: problem in running a expect script from crontab