SH Script Execution Problems with Cronjob


 
Thread Tools Search this Thread
Operating Systems AIX SH Script Execution Problems with Cronjob
# 1  
Old 06-30-2011
Question SH Script Execution Problems with Cronjob

Hi,

I have created a sh script to startup and shutdown the oracle database, when I execute the script thru command line it execute successfully, but when I call the script thru cronjob it does not execute.

The scripts are as follows:
Code:
 
LOG=/oracle/times.log
export ORACLE_SID=prod
echo $ORACLE_SID" Standby Database Open READ ONLY initiated   " `date` >> $LOG
sqlplus "/as sysdba"<<EOF
recover managed standby database cancel;
shutdown immediate;
startup mount;
alter database open read only;
EOF
echo $ORACLE_SID" Standby Database Open READ ONLY completed   " `date` >> $LOG

Code:
 
LOG=/oracle/times.log
export ORACLE_SID=prod
echo $ORACLE_SID" Standby Database Close READ ONLY initiated  " `date` >> $LOG
sqlplus "/as sysdba"<<EOF
shutdown immediate;
startup nomount;
alter database mount standby database;
alter database recover managed standby database disconnect from session;
EOF
echo $ORACLE_SID" Standby Database Close READ ONLY completed  " `date` >> $LOG
echo $ORACLE_SID" Standby Database Recovery Mode Started      " `date` >> $LOG
echo "===============================================================================" >> $LOG

Cron job is as follows:

Code:
 
00 0,9,12 * * * sh /oracle/scripts/standby_open_reporting.sh
00 2,21,13 * * * sh /oracle/scripts/standby_close_reporting.sh


Below is output of times.log file

Code:
prod Standby Database Close READ ONLY initiated   Wed Jun 29 21:00:00 PKST 2011
prod Standby Database Close READ ONLY completed   Wed Jun 29 21:00:00 PKST 2011
prod Standby Database Recovery Mode Started       Wed Jun 29 21:00:00 PKST 2011
===============================================================================
prod Standby Database Open READ ONLY initiated    Thu Jun 30 00:00:00 PKST 2011
prod Standby Database Open READ ONLY completed    Thu Jun 30 00:00:00 PKST 2011
prod Standby Database Close READ ONLY initiated   Thu Jun 30 02:00:00 PKST 2011
prod Standby Database Close READ ONLY completed   Thu Jun 30 02:00:00 PKST 2011
prod Standby Database Recovery Mode Started       Thu Jun 30 02:00:00 PKST 2011
===============================================================================
prod Standby Database Open READ ONLY initiated    Thu Jun 30 09:00:00 PKST 2011
prod Standby Database Open READ ONLY completed    Thu Jun 30 09:00:00 PKST 2011


Last edited by lodhi1978; 06-30-2011 at 05:36 AM.. Reason: adding log file output
# 2  
Old 06-30-2011
You need to set the proper environment variables.

so cron finds sqplplus
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 06-30-2011
Thanks!
I haved added the environment variables in my shell script and it is running fine now thru cron job.
Can I executed the .profile in shell script instead of adding the environment variables in shell script?
# 4  
Old 06-30-2011
you can add.

but instead of adding the .profile, you can create a file and out the necessary variables and source it
This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 06-30-2011
Question SH Script Execution Problems with Cronjob

Quote:
Originally Posted by itkamaraj
you can add.

but instead of adding the .profile, you can create a file and out the necessary variables and source it
Would you please advice how can I do that?
# 6  
Old 06-30-2011
see this example

Running SQLPlus and PL/SQL Commands From A Shell Script dbamac

Code:
 
. /usr/local/bin/oraenv

This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 06-30-2011
Quote:
Originally Posted by lodhi1978
Can I executed the .profile in shell script instead of adding the environment variables in shell script?
You probably use ksh as your scripting language. Then it is advisable to NEVER rely on any environment (like the one set in ~/.profile or ~/.kshrc) but always set it explicitly. This way you never have to worry about the script being called from command line, cron or wherever.

I have for this a central file /usr/local/lib/ksh/f_env where i store all the necessary PATH- and other environment-variables, do things i want done in all my scripts (for instance: start some logging so that if a script breaks i can at least find out where it was broken), etc.. All my scripts source in this script as the first thing to do. Here is an example:

Code:
#! /bin/ksh
# This is an example script

. /usr/local/lib/ksh/f_env

# here starts the scripts code
command_1
command_2
[...]
exit 0

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

2. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Good evening, ive got this cron to be run: if i run this manually it doesnt work,it takes me to the prompt again /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 here is the code fragment: coopge@coopge: opge PRODUCCION>more... (1 Reply)
Discussion started by: alexcol
1 Replies

3. Shell Programming and Scripting

Expect script Execution Problems .. Help!!!

Hi Guys, I am writing the expect script which take input from the txt file and check whether that file is present over the Sftp or not.If yes then delete other wise check the next one.. I am able to do comparison online for single file... Please also note still i didn't try to implement... (1 Reply)
Discussion started by: hackerdilli
1 Replies

4. Shell Programming and Scripting

Execution Problems

this my source file ************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length ... (6 Replies)
Discussion started by: teefa
6 Replies

5. Shell Programming and Scripting

Execution problems with BASH Shell Script

Hi I need help with my coding , first time I'm working with bash . What i must do is check if there is 3 .txt files if there is not 3 of them i must give an error code , if al three is there i must first arrange them in alphabetical order and then take the last word in al 3 of the .txt files... (1 Reply)
Discussion started by: linux newb
1 Replies

6. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

7. Shell Programming and Scripting

Execution Problems with bash script

Hello, can someone please help me to fix this script, I have a 2 files, one file has hostname information and second file has console information of the hosts in each line, I have written a script which actually reads each line in hostname file and should grep in the console file and paste the... (8 Replies)
Discussion started by: bobby320
8 Replies

8. OS X (Apple)

Execution Problems with ASU Shell Script

Hello. I have been trying to create a shell script that checks to see if there are software updates and if not, then exit the script. If so, then check to see if a user is logged in. If a user is logged in, it will only install the updates. If a user is not logged in, then it will display a... (3 Replies)
Discussion started by: Talcon
3 Replies

9. Shell Programming and Scripting

Problems in running a Perl script via cronjob

I have a very basic perl script that attempts to find if a process is running. If the process is not running then the script is supposed to start the process. If I execute the script from command line it works fine as expected. However if the script is executed via cronjob, the script cannot find... (1 Reply)
Discussion started by: ypant
1 Replies

10. Shell Programming and Scripting

Cronjob problems...

Hi All! I have a problem with one of my scripts. When I run the script from the command line : ./myscript.mac, it runs fine, but when I schedule it to run as a cronjob I get the following error : ----------------------------------------------------------------------------- Your "cron" job... (5 Replies)
Discussion started by: Jacovanderberg
5 Replies
Login or Register to Ask a Question