Sponsored Content
Full Discussion: Error handling
Top Forums Shell Programming and Scripting Error handling Post 302684663 by Learn4Life on Thursday 9th of August 2012 11:47:38 PM
Old 08-10-2012
Error handling

Hello fellow UNIX gurus Smilie

I have a problem regarding the script below:

Code:
# Variables used in this shell.
power=0        # Stores squared integer
total=0        # Sum of all squared integers
num=0        # Stores command line arguements


# Provides error handling if command line arguments are 0.
if [ $# = 0 ]; then
    echo "Usage $0 - integer-list"
    exit 1
fi


# Function that is used to sum all integers values
# from the power variable; store the sum in total variable. 
sum()
{
    total=`expr $total + $power`
}


# Iterate through the command line arguments, and store
# each integer in $num.
for num in $@; do
    if [ $num -ge 1 -a $num -le 65536 ]; then     
        # $num squared stored in power variable.
        power=`expr $num \* $num`
        # Output computation result.
        echo "$num squared equals = $power"
        # Call sum() function to evaluate the sum of
        # squared integers.
        sum
    # Else, if argument is over 65536, print user notification that 
    # the maximum number has been reached.
    elif [ $num -ge 65536 ]; then
        echo "65536 is the maximum number for this script"
        exit 1
    # Otherwise; when the arguments are not in range of 0-65536,
    # prompt user why shell executes prematurely.
    else
        # User notification.
        echo "$num is an invalid argument. Only natural numbers from 0 to 65536 are valid."
        # Exit shell script.
        exit 1
    fi
done

# Print out the sum of the sqaured number list.
echo "Total sum of the squared integers: $total"
# Exit shell script.
exit 0

Everything runs fine except when I type in a sting as argument I get the following error:

Code:
[: 63: Illegal number: string

I want that whatever input is provided a custom error message is printed instead of that error code above. Any hints on that are greatly appreciated.

-Daniel
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handling ftp error

I have a script which connects to remote server and ftp the files It works fine, however if there is any failure in ftp connection can it be handled??? ftp log ftp session start time is: Thu Jun 19 00:00:02 BST 2008 Not connected. Not connected. Interactive mode off. Not connected.... (1 Reply)
Discussion started by: vivek_damodaran
1 Replies

2. Shell Programming and Scripting

SFTP Error Handling

Hi , Can any one tell me is there any standard method to track errors during sftp ? using which command i can track sftp errors ? i tried using echo $? . Most of the times i am getting error number 127 ,1, 255. whether it is constant numbers ? Please help me out. Thanks in advance (2 Replies)
Discussion started by: deepusunil
2 Replies

3. Shell Programming and Scripting

Error Handling

Helo Experts, I need a help in handling errors in shell script, wants my errors displayed in text file instead of command window.. My shell script is here; cd /cygdrive/s/Files for FILES in ./*.* do temp=`basename $FILES` if cp $FILES /cygdrive/r/CopyFile1/$FILES; then echo "copy... (5 Replies)
Discussion started by: CelvinSaran
5 Replies

4. Shell Programming and Scripting

Finger and error handling

I have this segment of code : cmd = "finger -m " $1 " 2>/dev/null | head -1" cmd | getline userinfo close(cmd) Sometimes finger returns no such user when given a user id. With the redirection to the default trash file i am getting rid of any screen "finger:no such user" messages. I also want... (2 Replies)
Discussion started by: beatblaster666
2 Replies

5. Shell Programming and Scripting

Help with Error Handling on Script

Hi, I need your guys help again. I run a script which check for some process status in a loop. when i check the process some of the process could throw an error, how can i check that inside my script. Thanks, RR (3 Replies)
Discussion started by: rrb2009
3 Replies

6. Shell Programming and Scripting

Help needed with error handling

I am writing a wrapper to one of the .ksh script. The wrapper script should capture the error/fatal(if any) and exit out of the script. Here is the script: #!/bin/sh . main_script.ksh <arg1> <arg2> > mainscript.log 2>&1 cnt=`grep 'ERROR' -c mainscript.log` if ; then echo "Error" ... (6 Replies)
Discussion started by: stunnerz_84
6 Replies

7. Shell Programming and Scripting

PERL error handling

I have a PERL command line embedded in a UNIX script. The script doesn't handle errors coming out of this command. I'm processing large files and occassionally I run out of disk space and end up with half a file. perl -p -e 's/\n/\r\n/g' < TR_TMP_$4 > $4 How do I handle errors coming out... (1 Reply)
Discussion started by: OTChancy
1 Replies

8. Shell Programming and Scripting

Error Handling

Below code works for different databases i.e. MYSQL and ORACLE The problem is for MYSQL in Block: if ; $? taking value accordingly but in case of ORACLE $? is always taking this value as zero (0). That is the reason in Oracle it always going in else Block in any case.. :( and in case of ... (4 Replies)
Discussion started by: ambarginni
4 Replies

9. Shell Programming and Scripting

Expect Script Error Handling

Good Day Everyone, I was hoping to get a little insight into an expect script that I've written. Basically we have this expect script to perform an sftp upload, key authentication is not an option, and sftp is the only method supported by our vendor, thus the need for this. I want to be... (3 Replies)
Discussion started by: thaller
3 Replies

10. Shell Programming and Scripting

Error handling for file

Hi Guys, I got a csv with pipe delimted file and i want to check second column of the file has any alpha character becuase I am expecting only number in that, and if any alpha characters then it should throw an error Thanks in advance (1 Reply)
Discussion started by: Rizzu155
1 Replies
Mail::Message::Convert::HtmlFormatText(3pm)		User Contributed Perl Documentation	       Mail::Message::Convert::HtmlFormatText(3pm)

NAME
Mail::Message::Convert::HtmlFormatText - Convert HTML into Text INHERITANCE
Mail::Message::Convert::HtmlFormatText is a Mail::Message::Convert is a Mail::Reporter SYNOPSIS
use Mail::Message::Convert::HtmlFormatText; my $af = Mail::Message::Convert::HtmlFormatText->new; my $plain_body = $af->format($body); DESCRIPTION
Convert HTML/XHTML message body objects into plain text bodies using HTML::FormatText. This package requires HTML::TreeBuilder and HTML::FormatText which are not installed by default together with Mail::Box. See also Mail::Message::rebuild() with rule "text_alternative_for_html". Converters between message objects Other converters METHODS
Constructors Mail::Message::Convert::HtmlFormatText->new(OPTIONS) -Option --Defined in --Default fields Mail::Message::Convert <see description> leftmargin 3 log Mail::Reporter 'WARNINGS' rightmargin 72 trace Mail::Reporter 'WARNINGS' fields => NAMES|ARRAY-OF-NAMES|REGEXS leftmargin => INTEGER The column of the left margin, passed to the formatter. log => LEVEL rightmargin => INTEGER The column of the right margin, passed to the formatter. trace => LEVEL Converting $obj->format(BODY) Pass an html/xhtml encoded body, and a plain text body is returned. Characters are translated into Latin1. $obj->selectedFields(HEAD) See "Converting" in Mail::Message::Convert Error handling $obj->AUTOLOAD() See "Error handling" in Mail::Reporter $obj->addReport(OBJECT) See "Error handling" in Mail::Reporter $obj->defaultTrace([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK]) Mail::Message::Convert::HtmlFormatText->defaultTrace([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK]) See "Error handling" in Mail::Reporter $obj->errors() See "Error handling" in Mail::Reporter $obj->log([LEVEL [,STRINGS]]) Mail::Message::Convert::HtmlFormatText->log([LEVEL [,STRINGS]]) See "Error handling" in Mail::Reporter $obj->logPriority(LEVEL) Mail::Message::Convert::HtmlFormatText->logPriority(LEVEL) See "Error handling" in Mail::Reporter $obj->logSettings() See "Error handling" in Mail::Reporter $obj->notImplemented() See "Error handling" in Mail::Reporter $obj->report([LEVEL]) See "Error handling" in Mail::Reporter $obj->reportAll([LEVEL]) See "Error handling" in Mail::Reporter $obj->trace([LEVEL]) See "Error handling" in Mail::Reporter $obj->warnings() See "Error handling" in Mail::Reporter Cleanup $obj->DESTROY() See "Cleanup" in Mail::Reporter $obj->inGlobalDestruction() See "Cleanup" in Mail::Reporter DIAGNOSTICS
Error: Package $package does not implement $method. Fatal error: the specific package (or one of its superclasses) does not implement this method where it should. This message means that some other related classes do implement this method however the class at hand does not. Probably you should investigate this and probably inform the author of the package. SEE ALSO
This module is part of Mail-Box distribution version 2.105, built on May 07, 2012. Website: http://perl.overmeer.net/mailbox/ LICENSE
Copyrights 2001-2012 by [Mark Overmeer]. For other contributors see ChangeLog. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.14.2 2012-05-07 Mail::Message::Convert::HtmlFormatText(3pm)
All times are GMT -4. The time now is 08:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy