Why does this script not work? Please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why does this script not work? Please help
# 1  
Old 02-22-2007
Why does this script not work? Please help

I have created a Shell script to call 12 Oracle PL/SQL scripts to query some data and insert into a table. When I run shell scripts manually, it works very well. But when I schedule shell script in crontab, it will give the error message like this:

02/22/07 04:00:00: Database mydb.world is up and running.

02/22/07 04:00:00: Counting extraction records script started.

02/22/07 04:00:00: Error counting validation/PL_SQL_1.sql.
02/22/07 04:00:00: Exiting script.

It seems that crontab started to execute shell script, when it went to call PL/SQL scripts, it failed. So I think that I may missed something in crontab settings. But I don't know what it is after I man crontab. I also post a part of my shell script for your information. Please help me to solve this problem. Many thanks in advance.

Here is the code:

# Started to insert records into xxxx_rowcount table.
for filename in validation/cnt_xxxx_*.sql
do
sqlplus -s > temp.log 2>&1 db_stg/db_passwd@$ORACLE_SID @$filename
if [ $? = 0 ]
then date +"%D %T: $filename successully counted." >> row_count.log
else date +"%D %T: Error counting $filename." >> row_count.log
grep "ORA-" temp.log >> row_count.log
date +"%D %T: Exiting script." >> row_count.log
mail -s 'CAFMII Load: Unsuccessful. See log file for errors.' btmna@yahoo.com<row_count.log
exit 1
fi
done

Highlighted part is in error message. It seems that script couldn't count $filename. Do I need to add filecount=xx in the script. Please advise.
# 2  
Old 02-22-2007
why don't you try to execute your .profile before running the script.

like this:
Code:
. /Home Directory/.profile

# 3  
Old 02-22-2007
Thanks. Why do I need to execute .profile before executing this shell script?
Please give me more tips. Is this for the environment variables settings?
# 4  
Old 02-22-2007
Yes, it is for setting the environment. You mentioned that you were able to run the script successfully manually with your login and the same script was failing from the crontab. so the most obvious reason could be the environment settings present in your .profile file( it is executed every time you login so the environment settings are set as soon as you login). whenever the script is invoked from cron it does not execute the .profile file so the environment settings are missing and leading to the script failure.
# 5  
Old 02-22-2007
Your explanation may be correct. But I have other 3 shell scripts to be executed under the same user. Two of them do the same job to call many PL/SQL scripts to do the work. One of them was created recently and is to call two PL/SQL to do the work. I scheduled 3 shell scripts in crontab without running .profile. The same environment and Solaris shell on these shell scripts. This is why I am confused. I think it may be the coding in shell scripts that can not go through the list of PL/SQL files. The error message is not clear for me to identify the reason on this. But I will try your method to run .profile to make envirnment ready. Then I will report the result. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

2. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

3. UNIX for Dummies Questions & Answers

this cshell script does not work ??

Hi I am trying to put the following commands that i have to type manually at the cshell prompt into a cshell script startup.csh which is copied below echo $DISPLAY xhost + rsh ba08lo01 module load incisiv/102/10.20.035 setenv DISPLAY $DISPLAY When i run the script with source command... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

4. Shell Programming and Scripting

my script doesn't work :(

i have this script and when i ejecute it, the console tell me this " sintax error line 41 unexpected element "}" " is the sintaxis ok? #!/bin/bash if ;then { exit 0; } if ; then { sudo /etc/init.d/apache2 start; sudo /etc/init.d/mysql start; php5 & nautilus... (3 Replies)
Discussion started by: keiserx
3 Replies

5. Shell Programming and Scripting

Help can't get script to work how I need it to...

Hi thank you for anyone who responds. Here is my script: for i in `ls -1 | grep $1 | grep $2` do x=`echo $i | sed 's/\.Sent/\.Done/g'` echo mv $i DONE/$x echo "Is this OK?" read user_response case $user_response in "y"|"Y") mv $i DONE/$x echo mv $i DONE/$x;; *) ... (13 Replies)
Discussion started by: llsmr777
13 Replies

6. UNIX for Dummies Questions & Answers

Script syntax...does this work?

Hi all, I'm just a basic unix scripto...does the following lines work?? I saw this lines from a script I was about to modify, please take note that these are not the original directories and the sign ( " ) is in there. "/destination/directory" "/origin/directory" If I add a command line in... (3 Replies)
Discussion started by: 3rr0r_3rr0r
3 Replies

7. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

8. Shell Programming and Scripting

My script does not work - could you pls help?

Hi all, I put together a script that seems not working as I would like to and after spending hours to find the problem I decided to ask your help. The thing I am trying to do is call AWK command on the TRUE branch of if statement. Else branch should only print out a message to screen. This... (1 Reply)
Discussion started by: BearCheese
1 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. UNIX for Dummies Questions & Answers

Command work but not in SH script

Command works but not in SH At terminal if i type: scp test.tar.gz user1@server2:/home/user Everything run smoothly (keyed, no password need) At script , test.sh #!/bin/sh scp test.tar.gz user1@server2:/home/user Nothing happen and clue ? ? ? ? ? (3 Replies)
Discussion started by: cititester
3 Replies
Login or Register to Ask a Question