Operating System - HP-UX
1827809 Members
1943 Online
109969 Solutions
New Discussion

Re: Scripts run interactively , not under cron !!!

 
Dave Walley
Frequent Advisor

Scripts run interactively , not under cron !!!

Hi.

I have written a c shell script when run interactively works fine, when I submit it to run under cron, it says

sqlplus: Command not found.

I included in the script the line from the PATH pointing to where the sqlplus program is and I still get the same result.

Any advice?.

Thanking you in advance.

Dave
why do i do this to myself
16 REPLIES 16
Alex Glennie
Honored Contributor

Re: Scripts run interactively , not under cron !!!

Verify that $ORACLE_SID,$ORACLE_HOME, $PATH are set correctly perhaps include a print statement in your script ?
Victor BERRIDGE
Honored Contributor

Re: Scripts run interactively , not under cron !!!

Hi,
Have you reset all your env variables in your script? since cron doesnt read your .profile/.kshrc...

Good luck
James R. Ferguson
Acclaimed Contributor

Re: Scripts run interactively , not under cron !!!

Dave:

You can source your profile ahead of calling your script. This can/should be done in the crontab entry. Alternatively, you could source your profile within the script itself to provide the necessary environmental variables you need. Thirdly, you could create a new file which contains and exports the common variables needed for your application, and source (read) that within your standard profile, within standard scripts; and/or in a crontab stream.

...JRF...
John Palmer
Honored Contributor

Re: Scripts run interactively , not under cron !!!

cron provides only a very minimal environment to scripts that it issues. Try running the command 'env' from cron and you'll see what I mean.

Your script will have to set up thing like PATH and other variables that are normally setup by /etc/profile and your .profile or C shell equivalent.

As you are trying to run sqlplus, you will also have to setup the required ORACLE environment - ORACLE_HOME, ORACLE_SID, PATH and SHLIB_PATH (if Oracle 8) as well.

Oracle provide scripts for this like 'oraenv' which are normally placed in /usr/local/bin. In batch mode, they require that ORACLE_SID has already been exported.

Find out where the Oracle scripts have been installed and have a look at them. You can then call them as sub-scripts (. oraenv) from your cron'd script. Be aware that they are written for the Korn/Posix shell though.
James R. Ferguson
Acclaimed Contributor

Re: Scripts run interactively , not under cron !!!

Dave:

You can source your profile ahead of calling your script. This can/should be done in the crontab entry. Alternatively, you could source your profile within the script itself to provide the necessary environmental variables you need. Thirdly, you could create a new file which contains and exports the common variables needed for your application, and source (read) that within your standard profile, within standard scripts; and/or in a crontab stream.

...JRF...
Dave Walley
Frequent Advisor

Re: Scripts run interactively , not under cron !!!

Thank you for your replies, I have included all my env variables in the script but still no luck. How can I execute my .profile from within a c shell script. I have included it as the second line of the file.

Looking forward to hearing from you once again.

Dave
why do i do this to myself
James R. Ferguson
Acclaimed Contributor

Re: Scripts run interactively , not under cron !!!

Dave:

To source (read) a file within a script, put a dot (".") in front of the script name. For instance, to source a file called /myscript you would do:

. /myscript #...note the space between the dot and the script name.

...JRF...
Vikas Khator
Honored Contributor

Re: Scripts run interactively , not under cron !!!

Hi ,

If you still have problems , post your script and we will go from there .
Keep it simple
Dave Walley
Frequent Advisor

Re: Scripts run interactively , not under cron !!!

I have tried including the .profile amd the oraenv setup files but still not working. I attach the file for reference. As you will see I am trying to write to a file when particular criteria has been met.

Dave
why do i do this to myself
James R. Ferguson
Acclaimed Contributor

Re: Scripts run interactively , not under cron !!!

Dave:

Looking at your attachement, I would not expect it to work. Your script is a C-shell but you have sourced a Posix shell profile (i.e. the . .profile).

Try the following to debug your script:

# csh -n /# csh -v /
The -n option parses but does not execute commands. You can check syntax this way.

The -v option causes commands to be echoed to stdout after substitutions are made.

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Scripts run interactively , not under cron !!!

Dave:

BTW, while everyone has their preference, and while everyone is entitled, you will find that most people avoid the csh shell and/or aren't familar with its syntax. The POSIX shell (/usr/bin/sh) is the standard shell in HP-UX and provides the most solid foundation for scripting.

...JRF...
Paul Davies
Advisor

Re: Scripts run interactively , not under cron !!!

Hi!

New to HP-UX and this forum - From an AIX background but think this will help:

Try specifying the shell in the first line of the script. eg:

#!/usr/bin/csh

Certainly in AIX, Sun and Linux cron runs jobs by default with the Bourne shell so any other you need to specify. I would guess that your login session is a c shell hence in runs interactivly.

Hope it helps.

Paul.
Paul Davies
Advisor

Re: Scripts run interactively , not under cron !!!

Apologies for earlier message - just read Dave's attachment and see that he does have the #!/usr/bin/csh line in (though in the attachment it is not the very first line). I'll look closer next time! :-)
박수정
Advisor

Re: Scripts run interactively , not under cron !!!

Hi!

1. Your crontab editing

# crontab -e

1 1 * * * su - ora8 -c "/Path/./yourscript"

2. Try specifying the shell in the first
line of the your script.

#!/usr/bin/csh or #!/bin/csh

Alan Riggs
Honored Contributor

Re: Scripts run interactively , not under cron !!!

step 1)
replace ". .profile" with ". /home//.cshrc"

step2) make plans to replace all csh scripts with either perl or ksh/sh scripts.


Vikas Khator
Honored Contributor

Re: Scripts run interactively , not under cron !!!

Hi ,

I might be wrong but I think you need to "source filename" in c shell as against . ./filename.

Keep it simple