Sponsored Content
Top Forums Shell Programming and Scripting Display which test in the if/else is failing Post 302489709 by kshji on Friday 21st of January 2011 11:00:47 AM
Old 01-21-2011
I parse those datalines and comparing values.
I also create variable which name is column ATTRIBUTE_NAME. Possible to use variable and comparing those. Only example if needed.
Code:
# ... set variables and run commands, look original solution

msg=/var/tmp/$$.msg.txt
> $msg
err=""

for f in $SMARTMESSAGE1 $SMARTMESSAGE2
do
    data=0
    cat $f | while read line
    do
       # only datalines include values ...
        case "$line" in
                ID*ATTRIBUTE_NAME*) data=1 ; continue ;;
                SMART*Error*Log*Ver*) data=0 ; continue ;;
                "") continue ;;
        esac
        ((data==0)) && continue

        flds=($line)  # parse to array
        f2="${flds[1]}"
         nflds=${#flds[*]}
        ((nflds=nflds-1))
        lastfld="${flds[$nflds]}"
        # extra lines, example to create variable and set value
        f2=${f2//-/_}  # cariablename can't include - => change it to the _
        eval $f2=\""$lastfld"\"
        # extra end
        case "$f2" in
                Temperature_Celsius) ((lastfld > 40 )) && echo "$f $f2 $lastfld" >> $msg  && err="$err $f2";;
                *) ((lastfld > 0 )) && echo "$f $f2 $lastfld" >> $msg  && err="$err $f2" ;;
        esac
    done
done

SUBJECT="$SUBJECT $err"
lines=$(cat $msg | wc -l)
# if msg file include lines - we have something to tell
if ((lines < 1 ))
then
        # no problem
        echo "$(date) no problem" >> $LOG
        rm -f $msg 2>/dev/null
        exit 0
fi

# Houston - we have problem
# send mail
echo "Some problem, sending mail " >&2
date >> $msg
# sendmail here

# rm tmp file
rm -f $msg 2>/dev/null

 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

2. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

3. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

4. Shell Programming and Scripting

Test file script - if evaluation failing

I have a following script to evaluate if file exist in the directory and then archive it. #!/bin/bash #master directory scriptdir="/flex/sh/interfaces" #change this path only - all other paths are connected with it filedir="/flex/interfaces" #change this path only - all other paths are... (3 Replies)
Discussion started by: viallos
3 Replies

5. UNIX for Dummies Questions & Answers

Script test failing

Testing some old script developed by different user. #!/usr/bin/sh case "$0" in */*) cmd="$0";; *) cmd=`which "$0"`;; esac dir=`dirname "$cmd"` node="$dir/." echo $node below two simple tests are failing, I am not seeing any Control+M characters in the script file and I am not able... (4 Replies)
Discussion started by: srimitta
4 Replies

6. UNIX for Advanced & Expert Users

PERL DBD make test on Linux failing

I am installing Oracle DBD to PERL 5.16.3 and during make test , I am running into this error :rm -f blib/arch/auto/DBD/Oracle/Oracle.so LD_RUN_PATH="/opt/oracle/product/11.2.0/racdb11204/lib" gcc -m32 -shared -O2 -L/usr/local/lib -fstack-protector Oracle.o dbdimp.o oci8.o -o... (3 Replies)
Discussion started by: talashil
3 Replies
elf_errmsg(3ELF)					       ELF Library Functions						  elf_errmsg(3ELF)

NAME
elf_errmsg, elf_errno - error handling SYNOPSIS
cc [ flag ... ] file ... -lelf [ library ... ] #include <libelf.h> const char *elf_errmsg(int err); int elf_errno(void); DESCRIPTION
If an ELF library function fails, a program can call elf_errno() to retrieve the library's internal error number. As a side effect, this function resets the internal error number to 0, which indicates no error. The elf_errmsg() function takes an error number, err, and returns a null-terminated error message (with no trailing new-line) that describes the problem. A zero err retrieves a message for the most recent error. If no error has occurred, the return value is a null pointer (not a pointer to the null string). Using err of -1 also retrieves the most recent error, except it guarantees a non-null return value, even when no error has occurred. If no message is available for the given number, elf_errmsg() returns a pointer to an appropriate message. This function does not have the side effect of clearing the internal error number. EXAMPLES
Example 1: A sample program of calling the elf_errmsg() function. The following fragment clears the internal error number and checks it later for errors. Unless an error occurs after the first call to elf_errno(), the next call will return 0. (void)elf_errno(); /* processing ... */ while (more_to_do) { if ((err = elf_errno()) != 0) { /* print msg */ msg = elf_errmsg(err); } } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
elf(3ELF), libelf(3LIB), attributes(5) SunOS 5.10 11 Jul 2001 elf_errmsg(3ELF)
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy