09-04-2009
Error handling in Unix shell scripting
Hello,
I have written a shell script and suppose there is any error in the script. How i can do exception handling in shell script.for example i have below code
sqlplus -s <<uid>>/<<pwd>>@<<$ORACLE_SID>> <<EOF > 1_pid1.log
set pagesize 0
set feedback off
set heading off
set linesize 200
@ pid_file.sql
exit
EOD
when i run above code it should create log file with 1_pid1.log
but it was not working becuase at the last line i did spelling mistake and writtern "EOD" instead off "EOF".
So i just want to know, how can i do error handling in unix shell script.
Thanks in Advance,
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I need to write a script which analyses an invoice file, counting the amount of pages in the file to be printed per account number and per invoice. The account numbers are stored in another file which has instructions on what do with ach customers invoice as per their account number.
please... (6 Replies)
Discussion started by: la_burton
6 Replies
2. UNIX for Advanced & Expert Users
Hi,
I am using few ISQL statements to update and delete from a few tables in sybase, now i want to roll back the transaction when any of the statements fail.How i can i capture these errors in the shell scripts.Please advise.
Thanks,
Gopi (4 Replies)
Discussion started by: bhgopi
4 Replies
3. Shell Programming and Scripting
please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
4. Shell Programming and Scripting
how can i write content of a variable to a file?
how can i read standard output into a variable? (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies
5. Shell Programming and Scripting
Hi all,
Can anyone guide to get tricks for file handling in bash shell? Thanks in advance.
Thanks
Deepak (2 Replies)
Discussion started by: naw_deepak
2 Replies
6. Shell Programming and Scripting
Hi all
I've got a question regarding error handling in shell scripts. My background is mainly object oriented programming languages, but for a year or so I've been doing more and more (bash) shell scripting (which I quite enjoy by the way).
To handle errors in my scripts I... (3 Replies)
Discussion started by: script_man
3 Replies
7. Shell Programming and Scripting
Hi can some one let me know what is the meaning of
$#
$@
$_
@_ in unix shell scripting.
I really appreciate your time for replying to my post.
Thanks In Advance (4 Replies)
Discussion started by: einsteinBrain
4 Replies
8. UNIX for Dummies Questions & Answers
i am new to shell scripting and stuck at one place in my program.
i am reading data from one structured file and extracting some data from particular lines and then writing into the output file. In that reading input file line by line from while loop.
while read line
do
rectype=line... (7 Replies)
Discussion started by: reeta_shri
7 Replies
9. UNIX for Dummies Questions & Answers
Hello Experts,
I have the following questions to be discussed here at this esteemed discussion forum.
I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies
10. Programming
Hi All,
need help to complete the automation but stuck at a perticular situation
below is the code
<code>
fixed_function_name
{
code....
code....
variable_map=
{
a="/a"
b="/b"
c="/c"
so on...
} (7 Replies)
Discussion started by: yadavricky
7 Replies
exit(1) User Commands exit(1)
NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps
SYNOPSIS
sh
exit [n]
return [n]
csh
exit [ ( expr )]
goto label
ksh
*exit [n]
*return [n]
DESCRIPTION
sh
exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of
the last command executed (an EOF will also cause the shell to exit.)
return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe-
cuted.
csh
exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the
expression expr.
The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches
for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to
jump to a label that occurs between a while or for built-in command and its corresponding end.
ksh
exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8
bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing
a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit
except for a shell which has the ignoreeof option (See set below) turned on.
return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the
least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return
is invoked while not in a function or a '.' script, then it is the same as an exit.
On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari-
able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not
performed.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5)
SunOS 5.10 15 Apr 1994 exit(1)