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!

Problem in calling shell script from crontah

Status
Not open for further replies.

riteshch

Programmer
Jul 27, 2003
8
US
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
 
Paste your cron line here so we can see where you are going wrong.

Also confirm what you mean ">this script it is is not working" do you mean the loging in (expect) script or the remote script?

And you say ">When I run this script on command prompt, it runs fine" Again do you mean the loging in (expect) script or the remote script on the remote command line?

I would guess it is likly to be a path issue and it probably just requires a . somewhere.

Laurie.
 
Here is the crontab and other entries...

[sunil@homer eastLoad]$ echo $SHELL
/usr/bin/ksh
[sunil@homer eastLoad]$ pwd
/home/sunil/eastLoad
[sunil@homer eastLoad]$ ls runS*
runSigill

[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/runSigill


When I run it it on command prompt it does run the script "runScript" on the remote box and then it comes back...

but the same thing is not happeneing when i call it thru crontab.. its not even logged into the remote system..
 
Ok you run this on the command line as what user?
and is it that same users cron that you use to call it from?

How are you calling it from the command line ....

./runSigill or /home/sunil/eastLoad/runSigill or sh /home/sunil/eastLoad/runSigill ?

Normaly it would be because cron has no concept of the environment (users path etc) and the following would resolve that by calling the users profile ...

10 15 * * * . /home/sunil/eastLoad/runSigill
(the dot<space>/home...... indicates cron should read my profile and do the command) but this may or maynot be your problem! (NOTE: yes a space either side of the dot)

Is there any indication in /var/adm/messages ? run:
tail -f /var/adm/messages (TIP: Crtl+C to break out of tail)
in another console while your cron fires off and look for clues?

Laurie.



 
I tried using . /home/sunil/eastLoad/runSigill
and here are the messages which i get in mail...

[sunil@homer baais]$ mail
Mail version 8.1 6/6/93. Type ? for help.
&quot;/var/spool/mail/sunil&quot;: 1 message 1 new
>N 1 root@localhost.local Sun Jul 27 18:38 22/805 &quot;Cron <sunil@homer> . /home/sunil/eastLoad/r&quot;
&
Message 1:
From sunil Sun Jul 27 18:38:00 2003
Date: Sun, 27 Jul 2003 18:38:00 -0400
From: root@localhost.localdomain (Cron Daemon)
To: sunil@localhost.localdomain
Subject: Cron <sunil@homer> . /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>

/bin/sh: spawn: command not found
couldn't read file &quot;Password:&quot;: no such file or directory
/bin/sh: send: command not found
/bin/sh: send: command not found
/bin/sh: send: command not found
/bin/sh: interact: command not found


 
Ok try:

10 15 * * * /usr/bin/expect /home/sunil/eastLoad/runSigill

Space between ../expect & /home.....


Sorry its now midnight here (UK) so I'll resume later today

Good Luck
Laurie.
 
I tried but still Its not working... waits for pwd...though same from command prompt it work,..

Subject: Cron <sunil@homer> /usr/bin/expect /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:

 
Ok so we resolved the path issues with that one, NOW, I've been surfing most of the morning but this Expect stuff is a bit elusive but I see a number of issues relating to Expect & cron.

One thing I see from your original posting is there is no space after password: in your script, where as I see this on all other expect scripts I have come across!

For example here is a script that will set new root password on nNumber of machines:

foreach host &quot;remote0.mydomain.com ... remoteN.mydomain.com&quot; {
spawn telnet $host
expect &quot;login: &quot;
send &quot;myname\r&quot;
expect &quot;Password: &quot;
send &quot;mypassword\r&quot;
expect &quot;$ &quot;
send &quot;su\r&quot;
expect &quot;password: &quot;
send &quot;rootpassword\r&quot;
expect &quot;# &quot;
send &quot;passwd root\r&quot;
# Here, we look for either of two strings, like an if/else construct
expect {
&quot;password: &quot; {
send &quot;rootnewpassword\r&quot;
exp_continue
}
&quot;# &quot; {
send &quot;exit\r&quot;
}
}
expect &quot;$ &quot;
send &quot;exit\r&quot;
}
__________________________________________________
Why your script works from the command line but not under cron now we have resolved the path issue I'm just not sure.

This is the first time I have looked at Expect so I'm driving blind, can I suggest that if the space does not fixit, you start a new post with a title of &quot;HELP NEEDED WITH EXPECT & CRON&quot; and maybe we can find an expert out here somewhere?

Sorry,
Laurie.
 
I tried with spaces but same result...

As you suggested I'll start a new post and hopefully there I'll find an answer ...

thanks a ton Laurie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top