Sponsored Content
Top Forums Shell Programming and Scripting Please review error routines in my ksh script Post 302675307 by peleton on Sunday 22nd of July 2012 09:40:52 PM
Old 07-22-2012
Please review error routines in my ksh script

The script distributes files from an AIX server using iether ftp or sftp depending on the constraint of the destination server. I am interested in having the error checking routine critically reviewed. I will only include an excerpt from the script concerning error trapping: (where $FTP_OUT is the log captured for either an "ftp" or an "sfpt" transfer)
Code:
Check_for_errors()
{
      set -x


      RESULT=`egrep -c "not found|No such|refused|failed|error|timed out|not exist|denied|Connection closed|STOR fails|not authorized|timeout|Not connected" $FTP_OUT`
      if [[ ! -s $FTP_OUT ]] ; then
         error_reporting
         ERROR_MSG="** FAILURE **"
         echo "    No $ftpflag log file produced" >> $TEMP_LOGF
         echo "    Abandoning transfer. " >> $TEMP_LOGF
      elif [[ $RESULT -gt 0 ]] ; then
         # The existence of "Transfer Complete" doesn't guarentee a successful result, however it must be present for a successfil result.
         # Checking for it's existance excludes the possibility of a null log file or an unknown error type.
         error_reporting
         ERROR_MSG="** FAILURE **"
      else
         echo "    FTP Success for interface $ftpflag ::: ${ftpfile} " >> $TEMP_LOGF
      fi
      rm -f $FTP_CMD
      rm -f $FTP_OUT
}


Last edited by Franklin52; 07-24-2012 at 08:27 AM.. Reason: Please use code tags for data and code samples, thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

error in ksh script

Hi, i am facing an error in the following script in the korn shell but in bash it is working , can any help me to convert the below script to korn shell script without errors. echo 123.4566 | bc -l | awk -F '.' '{ print $1; exit; }' Thanks in advance kamal (5 Replies)
Discussion started by: G.K.K
5 Replies

2. Shell Programming and Scripting

Review the Shell Script

Hi, I want to copy all the log file except current date log from one server to another server. Log File will be like this LOGNIG_08_11_2008*.log For this cd /test/log date -d '1 day ago' "+%d_%m_%Y" -->This command gives previous day scp LOGSNIG_date -d '1 day ago' "+%d_%m_%Y"... (2 Replies)
Discussion started by: srinivasvandana
2 Replies

3. Shell Programming and Scripting

Please, review script.

Hi guys, I 've been brewing this shellscript, but I can't test it until next tuesday. In the meantime I am too curious wether it will work or not, so I'd like to hear your comments. Background: I want to watch the user quota for mailboxes in various email-domains on a IMAP-server. I have... (1 Reply)
Discussion started by: algernonz
1 Replies

4. Shell Programming and Scripting

can we use routines of datastage in unix script

Hi all, My aim is to get the log details of datastage job using unix scipt. we know that DSjob are used to get the log details from datastage universe through the adminstrator.can we call that DSjob rountine in our unix script. Thanks in advance Regards, NimmyRaju:) (0 Replies)
Discussion started by: nimmyraju
0 Replies

5. Shell Programming and Scripting

a shell script for review.

I have written a bit of shell that lets our company check all our SSL certs. the aim is to have a list of servers and run this check from cron once a week. Our managers have decided that we will not run BASH, so it has been written in /bin/sh and only needs openssl, no perl, no bash, no extra... (8 Replies)
Discussion started by: robsonde
8 Replies

6. Shell Programming and Scripting

Please review script for search in all files

I have written a little script to scan users home directories for certain commands located inside a file. The script is setup to include a small help section and allows for passing a username argument to override scanning of all users home directories. A lot of searching and trial and error has... (7 Replies)
Discussion started by: bkeep
7 Replies

7. Shell Programming and Scripting

assistance needed to add 2 other routines to my script

Hello guys, In my script, I need to add two other routines where I Manipulate the files with a 'x' The routine looks at CLI named qip-getobjectprof that references a input file named hosts_list.txt Then I use the CLI named qip-setobject to set the orignal name with an 'x'and move the... (3 Replies)
Discussion started by: richsark
3 Replies

8. Shell Programming and Scripting

Ksh Shell Script Error

Hi, While running below code i am getting error as below 0403-004 Specify a parameter with this command. Please look it below code and let me know about if condition. Code is As below #!/usr/bin/ksh Infa_Src_Dir=$DIR/SrcFiles/pp Load_Info_Lst_Path=$DIR/SrcFiles/pp... (1 Reply)
Discussion started by: samadhanpatil
1 Replies

9. Shell Programming and Scripting

ksh Script - Syntax error `done' unexpected

Hello, I am working on my first ksh script to review daily reports. The script uses different functions to check different types of reports in csv format. A control file gets read in with information regarding the report, other info, and the function to use. When I run the script I get the... (4 Replies)
Discussion started by: bot9196
4 Replies

10. UNIX for Beginners Questions & Answers

Error in ksh script: missing right bracket

I have no idea how to write ksh script, but i'm really in need of help with this. I using fedora 30 and in attempt of runnig attached script i getting those errors, i solved first error by removing excess bracket, but i do not know what should i do with other. Pls sorry for trash post. (8 Replies)
Discussion started by: NullPtr
8 Replies
SET_ERROR_HANDLER(3)							 1						      SET_ERROR_HANDLER(3)

set_error_handler - Sets a user-defined error handler function

SYNOPSIS
mixed set_error_handler (callable $error_handler, [int $error_types = E_ALL | E_STRICT]) DESCRIPTION
Sets a user function ($error_handler) to handle errors in a script. This function can be used for defining your own way of handling errors during runtime, for example in applications in which you need to do cleanup of data/files when a critical error happens, or when you need to trigger an error under certain conditions (using trig- ger_error(3)). It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by $error_types unless the callback function returns FALSE. error_reporting(3) settings will have no effect and your error handler will be called regard- less - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator. Also note that it is your responsibility to die(3) if necessary. If the error-handler function returns, script execution will continue with the next statement after the one that caused an error. The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler(3) is called. If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time. PARAMETERS
o $error_handler - A callback with the following signature. NULL may be passed instead, to reset this handler to its default state. Instead of a function name, an array containing an object reference and a method name can also be supplied. bool handler (int $errno, string $errstr, [string $errfile], [int $errline], [array $errcontext]) o $errno - The first parameter, $errno, contains the level of the error raised, as an integer. o $errstr - The second parameter, $errstr, contains the error message, as a string. o $errfile - The third parameter is optional, $errfile, which contains the filename that the error was raised in, as a string. o $errline - The fourth parameter is optional, $errline, which contains the line number the error was raised at, as an integer. o $errcontext - The fifth parameter is optional, $errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, $errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context. If the function returns FALSE then the normal error handler continues. o $error_types - Can be used to mask the triggering of the $error_handler function just like the error_reporting ini setting controls which errors are shown. Without this mask set the $error_handler will be called for every error regardless to the setting of the error_reporting setting. RETURN VALUES
Returns a string containing the previously defined error handler (if any). If the built-in error handler is used NULL is returned. NULL is also returned in case of an error such as an invalid callback. If the previous error handler was a class method, this function will return an indexed array with the class and the method name. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.5.0 | | | | | | | $error_handler now accepts NULL. | | | | | 5.2.0 | | | | | | | The error handler must return FALSE to populate | | | $php_errormsg. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 Error handling with set_error_handler(3) and trigger_error(3) The example below shows the handling of internal exceptions by triggering errors and handling them with a user defined function: <?php // error handler function function myErrorHandler($errno, $errstr, $errfile, $errline) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting return; } switch ($errno) { case E_USER_ERROR: echo "<b>My ERROR</b> [$errno] $errstr<br /> "; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br /> "; echo "Aborting...<br /> "; exit(1); break; case E_USER_WARNING: echo "<b>My WARNING</b> [$errno] $errstr<br /> "; break; case E_USER_NOTICE: echo "<b>My NOTICE</b> [$errno] $errstr<br /> "; break; default: echo "Unknown error type: [$errno] $errstr<br /> "; break; } /* Don't execute PHP internal error handler */ return true; } // function to test the error handling function scale_by_log($vect, $scale) { if (!is_numeric($scale) || $scale <= 0) { trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR); } if (!is_array($vect)) { trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING); return null; } $temp = array(); foreach($vect as $pos => $value) { if (!is_numeric($value)) { trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE); $value = 0; } $temp[$pos] = log($scale) * $value; } return $temp; } // set to the user defined error handler $old_error_handler = set_error_handler("myErrorHandler"); // trigger some errors, first define a mixed array with a non-numeric item echo "vector a "; $a = array(2, 3, "foo", 5.5, 43.3, 21.11); print_r($a); // now generate second array echo "---- vector b - a notice (b = log(PI) * a) "; /* Value at position $pos is not a number, using 0 (zero) */ $b = scale_by_log($a, M_PI); print_r($b); // this is trouble, we pass a string instead of an array echo "---- vector c - a warning "; /* Incorrect input vector, array of values expected */ $c = scale_by_log("not array", 2.3); var_dump($c); // NULL // this is a critical error, log of zero or negative number is undefined echo "---- vector d - fatal error "; /* log(x) for x <= 0 is undefined, you used: scale = $scale" */ $d = scale_by_log($a, -2.5); var_dump($d); // Never reached ?> The above example will output something similar to: vector a Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) ---- vector b - a notice (b = log(PI) * a) <b>My NOTICE</b> [1024] Value at position 2 is not a number, using 0 (zero)<br /> Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) ---- vector c - a warning <b>My WARNING</b> [512] Incorrect input vector, array of values expected<br /> NULL ---- vector d - fatal error <b>My ERROR</b> [256] log(x) for x <= 0 is undefined, you used: scale = -2.5<br /> Fatal error on line 35 in file trigger_error.php, PHP 5.2.1 (FreeBSD)<br /> Aborting...<br /> SEE ALSO
ErrorException, error_reporting(3), restore_error_handler(3), trigger_error(3), error level constants, information about the callback type. PHP Documentation Group SET_ERROR_HANDLER(3)
All times are GMT -4. The time now is 11:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy