LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-14-2005, 02:05 AM   #1
ruchitadesai
LQ Newbie
 
Registered: Mar 2005
Location: India
Posts: 7

Rep: Reputation: 0
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.
 
Old 03-14-2005, 02:18 AM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
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
 
Old 03-17-2005, 03:36 AM   #3
ruchitadesai
LQ Newbie
 
Registered: Mar 2005
Location: India
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks a lot for ur help.
 
Old 03-17-2005, 03:51 AM   #4
ruchitadesai
LQ Newbie
 
Registered: Mar 2005
Location: India
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 03-17-2005, 04:21 AM   #5
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
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
 
Old 03-17-2005, 08:08 AM   #6
ruchitadesai
LQ Newbie
 
Registered: Mar 2005
Location: India
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 03-17-2005, 08:36 AM   #7
hk_linux
Member
 
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95

Rep: Reputation: 15
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)
 
Old 05-27-2005, 04:12 AM   #8
ruchitadesai
LQ Newbie
 
Registered: Mar 2005
Location: India
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 05-27-2005, 04:15 AM   #9
ruchitadesai
LQ Newbie
 
Registered: Mar 2005
Location: India
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 05-27-2005, 04:34 AM   #10
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job with a Script bravored Linux - General 4 08-05-2005 10:27 AM
Cron Job not running ssh script karim0028 Linux - General 3 02-07-2005 12:08 PM
Trouble with perl script in Cron job thack111 Linux - General 7 11-25-2004 02:44 AM
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 11:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration