![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 Code:
else DBDOWN=0 Code:
if [ $? -eq 1 ] then DBDOWN=0 else DBDOWN=1 fi 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 Carl |
|
|||
|
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. |
|
|||
|
Quote:
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 |
|||
| Google UNIX.COM |