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
# 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
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
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.
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:
and
Usually it's something like:
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:
Also, $? is a numeric value so use "-eq" vs "=". It'll probably work but it's always good to use the correct syntax.
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.
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.
I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only..
it... (6 Replies)
Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only..
it... (1 Reply)
Hi
As per my requirement when I run . ./file.sh am getting the following error
-bash:ELF: command not found
when i execute as ./file.sh it is getting executed.How to resolve this.
Thanks in advance. (3 Replies)
Hi,
I am having a shell script which has a while loop as shown below.
while
do
sleep 60
done
I am executing this script from Informatica ETL tool command task from where we can execute UNIX commands/scripts. When i do that, i am seeing 2 processes getting started for one script... (2 Replies)
I made a shell script to execute a server in screen mode.
# start server
screen -d -m -S Test ./application
echo "Program Started Successfully"
than I'm executing it from php by
echo shell_exec('/home/script.sh');
and it is giving me this error.
"cannot make directory... (1 Reply)
Hi, need help, I would like to know what is this IF statement trying to do? When the script is executing and error out with line 9 which is the IF statement line.
if ]
then
TOPDIR=$(pwd)
else
TOPDIR=${0%/*}
fi
TOPDIR=${TOPDIR%/*}
the log file.
Current system time is... (15 Replies)
Please help - I have seen others ask this question but I need a simple example of using vi in a shell script. Once I enter VI the shell script does not execute the next commands until I q!. I invoke VI and start the edit process. I want to go to the third line and replace a character with a new... (2 Replies)
I have the following crontab entry to run a shell script for every 30 minutes of every day:
30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log
after I created the crontab file I have also done:
$crontab my_crontab
I also check to make sure it exists, by using the following... (11 Replies)