10-14-2013
When I write a script that only I will be running and I know that I will pay attention to any diagnostics my script produces and know how to fix it, I may omit some of the error checking.
When I provide sample code for the UNIX & Linux Forums, I occasionally put in error checking but generally assume that I'm writing samples rather than production code. If someone wants to put my samples into their production code, it is their job to make it bulletproof.
If I'm writing code for production use, I check the exit status of almost everything. (However, I seldom check the exit status of writing diagnostic messages. If they fail, what are you going to do -- write another diagnostic that will probably also fail???)
I pretty much follow the same philosophy when verifying that command line parameters and data being processed from user-supplied files are in the format needed to get the job done.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Could someone please advise on a good way to implement error checking in a script?
i am taking input from a file, iserting it's values into two commands and sending the output of each to seperate log files. i need to check those log files for for an occurance of 'error', stop the command if... (3 Replies)
Discussion started by: gubten
3 Replies
2. Shell Programming and Scripting
Here is my problem
I'm designing a script that will have to accept user input from the command line using the read command.
The problem is that I have to check the input which should be in the format of
<first name> <last name> <phone number (8 digits long)>
The input can also be
... (4 Replies)
Discussion started by: pokeycam
4 Replies
3. Shell Programming and Scripting
I'm trying to create a directory from my Perl script. Only if the there was an error I want to let the user know about it. So if the folder exists is ok.
This is what I think should work:
`mkdir log 2>/dev/null`;
if($? == 0 || $? == errorCodeForFileExists)
{ everyting is fine }
else
{... (3 Replies)
Discussion started by: jepombar
3 Replies
4. Shell Programming and Scripting
I am creating a script that will automatically use sftp to connect to a site and download a file, extract the tar and then delete the tar file once completed.
What I am stuck on is the error checking for this process.
Here is the code so far:
Now this works for me as is, but i need... (0 Replies)
Discussion started by: xianoth
0 Replies
5. Shell Programming and Scripting
HI all;
I am new to the KSH scripting and i was asked to do some error checking using KSH,in the log file, i donot know how to do error checking ,so please let me know some tips and the vague code if possible.
Thanks in anticipation
vinay (1 Reply)
Discussion started by: vinayrao
1 Replies
6. Shell Programming and Scripting
Dear friends,
I am using the below command in my unix script
-----------------------------------------------
File_Name=`ls $CTRY*$DATE_SUFFIX*zip` --> Command-1
.....
if
then
unzip -a $File_Name -d $CTRY_DIR/$CTRY
else
echo "File for $CTRY dated $DATE_SUFFIX does not exist... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies
7. Programming
Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database.
Code:
string NewMovie = "ww";
string queryText ;
queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'";
... (1 Reply)
Discussion started by: gregarion
1 Replies
8. Programming
I have some unstable mistake in my program and out-of-idea how to catch it.
I am looking for advice with a way to work it out!
I have in a pretty complicated program (but one source file) set of int-counters - 15, if exactly.
Lately, on final printout I have inpossible value (I am... (3 Replies)
Discussion started by: alex_5161
3 Replies
9. Shell Programming and Scripting
I am currently wrapping up a assignment for one of my classes. I need help writing some error checking logic. The problems I am having are:
keeping track of the records I have deleted and reported it back using echo.
I have no idea how to do this.
ensuring that line numbers fall... (1 Reply)
Discussion started by: Boltftw
1 Replies
10. UNIX for Beginners Questions & Answers
Hi Folks -
I want to add error handling to a portion of a *.ksh, but I'm having difficulty doing so in an easily digestible way.
Essentially, I want to echo weather it was successful or unsuccessful after each command.
Here is the code I need to add error handling to:
perl... (2 Replies)
Discussion started by: SIMMS7400
2 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)