The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Verifying if the shell command executed or not? eamani_sun Shell Programming and Scripting 3 05-13-2008 12:18 AM
Local shell script need to be executed on a remote linux box rajeshomallur Linux 6 05-02-2008 10:05 AM
perl - why is the shell script executed before the print command? mjays Shell Programming and Scripting 3 09-21-2007 02:49 AM
Help - Need simple example of VI executed in shell script corsart AIX 2 06-03-2006 03:25 PM
Shell script doesn't get executed using crontab radhika Shell Programming and Scripting 11 06-09-2005 01:28 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Nov 2005
Posts: 127
Unix shell script couldn't be executed. Pls help!

I have wrriten a script to call sql script to do some work in database. However, the script couldn't be executed. The only information was: ksh: ./updt_attrib.ksh cannot execute. Please help me to identify where the problem is. I post script here for your reference. Thanks a lot.


#!/bin/ksh

# Created By: duke0001
# Created On: 9/14/06
# Description: This script update xxx information for xxxx
# attributes tables.

# Check to make sure the correct number of parameters have been enetered.
#if [[ $# -lt 1 ]] then
# echo "Incorrect number of parameters."
# echo "Usage: $0 [ORACLE_SID]"
# exit 1
# fi

#Initialize variables.
ORACLE_SID=$1
ORACLE_HOME=/oracle/product/9.2.0
WORK_DIR=`dirname $0`
MINUTES=0
#FILECOUNT=0
#FILETRANSFERED=1
DBDOWN=1

# Change to working directory.
cd $WORK_DIR

# Set environment variables.
export ORACLE_SID
export ORACLE_HOME
export PATH=$PATH:/oracle/product/9.2.0:/oracle/product/9.2.0/bin

# Check to make sure that the database is available.
while [ $DBDOWN -eq 1 ]
do
sqlplus -s > /dev/null 2>&1 "dbuser/password@$ORACLE_SID" <<EOF
whenever sqlerror exit 1
select * from dual;
exit 0
EOF

if [ $? = 1 ]
then DBDOWN=1
date +"%D %T: Still waiting for $ORACLE_SID to become available." >> updt_attrib.log
sleep 60
else DBDOWN=0
fi
done

date +"%D %T: Database $ORACLE_SID is up and running." >> updt_attrib.log
echo "" >> updt_attrib.log

date +"%D %T: update attributes script started." >> updt_attrib.log
sqlplus -s > temp.log 2>&1 dbuser/passwd@$database @tools/updt_attrib.sql

if [ $? = 0 ]
then date +"%D %T: $scripts successfully executed." >> updt_attrib.log
else date +"%D %T: Error executing script." >> updt_attrib.log
grep "ORA-" temp.log >> updt_attrib.log
date +"%D %T: Exiting script." >> updt_attrib.log
mail -s 'DB Update: Unsuccessful. See Log file for errors.'
duke0001@company.com<updt_attrib.log
exit 1
fi
done

date +"%D %T: End update attributes in xxx data warehouse." >> updt_attrib.log
mail -s 'End update attributes in xxx data warehouse.' duke0001@company.com<updt_attrib.log
exit 0
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Aug 2006
Posts: 22
Check if ksh is in /bin directory.
Reply With Quote
  #3 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Nov 2005
Posts: 127
I think ksh is in /bin directory because there is another script with #!/bin/ksh
over there and it has been executed for years. By the way, what about the script itself? Is there any coding problem? Thanks.
Reply With Quote
  #4 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 382
What are the perms on the script? It needs to have execute bit turned on.

chmod +x updt_attrib.ksh

Carl
Reply With Quote
  #5 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 382
As far as the script, you might consider indenting the info in loops and if statements to make the more readable.

Most scripts I've seen don't do:

Code:
then DBDOWN=1
and

Code:
else DBDOWN=0
Usually it's something like:

Code:
if [ $? -eq 1 ]
then
  DBDOWN=0
else
  DBDOWN=1
fi
That way it's easier to see what code belongs with which part of a statement.

Yea, that while loop. I didn't realize it was a large as it was until I looked a little harder. It initially looked like an infinite loop.

And you're going to need to echo something to the mail statements. At least on the one I just tested it on, mail is looking for a body to pass along. So something like:

Code:
echo "SQL Failure" | mail -s "subjectline text" test@company.com
Also, $? is a numeric value so use "-eq" vs "=". It'll probably work but it's always good to use the correct syntax.

Carl
Reply With Quote
  #6 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Nov 2005
Posts: 127
Carl:

Thanks a lot for your advice. I am new to shell script and would like to learn more on it. Is there any good book could you recommand? I will check my script with your advice and come back to report the result. Thanks again.
Reply With Quote
  #7 (permalink)  
Old 09-14-2006
Registered User
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 382
Quote:
Originally Posted by duke0001
Carl:

Thanks a lot for your advice. I am new to shell script and would like to learn more on it. Is there any good book could you recommand? I will check my script with your advice and come back to report the result. Thanks again.
There may be other errors in your script. Those are the ones that jumped out while I was waiting on some patching I was doing.

To learn about the korn shell specifically, I'd suggest Learning the Korn Shell published by O'Reilly.

A nice reference that goes through multiple shells (ksh, bash, csh, sh, etc) would be Shell Scripting by Example.

I used both books when I was creating my scripting class. The nice thing about the second book is it lists a bunch of commonly used utilities. I picked up a little knowledge of some of the more obscure unix tools by running man tool.

Carl
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0