LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   cron job for expect script (https://www.linuxquestions.org/questions/programming-9/cron-job-for-expect-script-301354/)

ruchitadesai 03-14-2005 03:05 AM

cron job for expect script
 
I have written a script using Expect tool and obviously Tcl.
Now, this script gives an output as desired when run on the shell prompt.
However, when a cron is set to execute this script every 15 mins, it send mail saying that the program that im trying to spawn using the script is not found and that the process is invoked frm within.

If any body can help me with this issue.......it would b great.
I jus wanna know what are the checkpoints that are to b considered for the script to run in cron job.
And where am i missing out on them. Also, when do we get such an eoor message in the mail when executed in the cron.

Thanks in advance.

nixcraft 03-14-2005 03:18 AM

Make sure at top of script you have
Code:

#!/usr/bin/expect -f
Script has executable permission
Code:

chmod +x /path/to/my.exp
Hope this helps

ruchitadesai 03-17-2005 04:36 AM

Thanks a lot for ur help.

ruchitadesai 03-17-2005 04:51 AM

Hi,
Thanks again for ur help.
I had included the code #! /usr/bin/expect -f at the start of my script.
Also, the script is executable as it runs on the shell properly giving desired output.
What else do i need to check in that case.

Ruchita

kees-jan 03-17-2005 05:21 AM

What is the exact error message? Please copy it from your mail and post it here.

I suspect your PATH is wrong.

Groetjes,

Kees-Jan

ruchitadesai 03-17-2005 09:08 AM

tHE ERROR MESSAGE THAT I GET WHEN MY SCRIPT IS SET ON CRON IS :

bash: couldnt execute "THE spawned APPLICATION"no such file or directory.
while executing
" spawn application mo_ip"
(procedure "do_attempt" line 5)
invoked from within
" do_attempt $app_name $mo_ip"
(file ./sysusage line30 )


Here i cannot reveal the applicationinvoke and hence used APPLICATION instead.

Using the script im trying to invoke an applicationthat gives me some system details.
I give username and password to start the applicationand cmd which i want o/p.
Also note that once my application starts the prompt is APPLICATION Name >
and not the normal shell prompt $.

Thanks,
Ruchita

hk_linux 03-17-2005 09:36 AM

hi,
This looks like the problem of the exe not present in the path.

In the expect script try,
spawn APPLICATION_WITH_FULL_PATH mo_ip

Then call from the crontab.

While executing from the command line, the application u r trying to execute would have been in the path. (probably it would been added from the .bashrc)

ruchitadesai 05-27-2005 05:12 AM

The Expect script is in the Home directory .

The script looks like this :
#! /usr/bin/expect -f
set d [timestamp -format %H%d%m]
log_file -a sysusage_$d.txt
set prompt "APPL> "
global argc
if { $argc !=0 } {
send_user "Invalid number of args"
send_user "Usage: $argv0"
exit -1
}
set server_ip x.x.x.x
set app_name y
set timeout 5
proc do_attempt { app_name server_ip } {
global prompt
set timeout 5
log_user 0
spawn appl -i $server_ip
expect "login: " { send "login\r" }
expect "password: " { send "password\r" }
expect "WMS-TL1> " { send "command;\r" }
expect {
-re "More..." {
send "\r";
exp_continue;
}
expect "APPL> " { send "exit\r" }
}
}
do_attempt $app_name $server_ip;
exit

ruchitadesai 05-27-2005 05:15 AM

the above mentioned script runs well on the promp but not when a cron job is set.
The error message it gives is given above in the mail chain.

Kindly suggest as to what else can i add to run it as a cron job.

kees-jan 05-27-2005 05:34 AM

Like mentioned above, the application to be spawned cannot be found when running from cron.

Either use the full path to the application in the script, or make sure the path is set correctly.

Groetjes,

Kees-jan


All times are GMT -5. The time now is 01:13 AM.