Sponsored Content
Top Forums Shell Programming and Scripting 0403-057 Syntax error at line 17 : `(' is not expected. Post 302989675 by abodage on Tuesday 17th of January 2017 06:38:22 AM
Old 01-17-2017
Bug 0403-057 Syntax error at line 17 : `(' is not expected.

Hi,

While executing my code i am getting below Error:
Code:
./check_disk1[55]: 0403-057 Syntax error at line 55 : `(' is not expected.

My code is :

Code:
#!/bin/ksh

PROGNAME=`basename $0`
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

OS=$(uname)
AWK="/usr/bin/awk"
GREP="/usr/bin/grep"
DF="/usr/bin/df"

#############################
# Functions
#############################

print_help() {
echo ""
echo "$PROGNAME is a Nagios plugin used to check disk used space by"
echo "processing the output of \"df\" command. It runs on UNIX, Linux"
echo "and BSD platforms and reports the following performance data:"
echo "- total disk space (Bytes)"
echo "- currently used disk space (Bytes)"
echo "- currently used disk space (%)"
echo " "
echo "$PROGNAME Warning Critical Partition"
echo " "
}

WarnSpace=$1
CritSpace=$2
Partition=$3

CRITICAL_CONDITION=95
WARNING_CONDITION=90

# float number comparison
function fcomp() {
    $AWK -v n1=$1 -v n2=$2 'BEGIN{ if (n1<=n2) exit 0; exit 1}'
}


#formats bytes => KBytes, MBytes, GBytes, TBytes
function UNIX_btokmgt() {
        if [ $1 -lt 512 ]; then                  #KBytes
             echo "${1}KB"
        elif [ $1 -lt 262144 ]; then             #MBytes
             echo "$1" | $AWK '{printf "%.1fMB", $1/512}'
        elif [ $1 -lt 134217728 ]; then          #GBytes
             echo "$1" | $AWK '{printf "%.1fGB", ($1*512)/1073741824}'
        elif [ $1 -gt 134217728 ]; then        #TBytes
             echo "$1" | $AWK '{printf "%.1fTB",($1*512)/1099511627776}'
        fi
}

function btokmgt() {
        if [ $1 -lt 1024 ]; then                 #Bytes
             echo "${1}B"
        elif [ $1 -lt 1048576 ]; then            #KBytes
             echo "$1" | $AWK '{printf "%.1fKB", $1/1024}'
        elif [ $1 -lt 1073741824 ]; then         #MBytes
             echo "$1" | $AWK '{printf "%.1fMB", $1/1048576}'
        elif [ $1 -lt 1099511627776 ]; then      #GBytes
             echo "$1" | $AWK '{printf "%.1fGB", $1/1073741824}'
        elif [ $1 -lt 1125899906842624 ]; then   #TBytes
             echo "$1" | $AWK '{printf "%.1fTB", $1/1099511627776}'
        fi
}

if [ $# -lt 1 ]; then
    print_help
    RESULT="UNKNOWN"
    RETURN_STATUS=$STATE_UNKNOWN
    exit $RETURN_STATUS
fi


if fcomp $WarnSpace 0
then
    WarnSpace=0
fi
if fcomp 100 $WarnSpace
then
    WarnSpace=100
fi

if fcomp $CritSpace 0
then
    CritSpace=0
fi
if fcomp 100 $CritSpace
then
    CritSpace=100
fi

if fcomp $CritSpace $WarnSpace
then
    WarnSpace=$CritSpace
fi


if [[ $OS == AIX ]]; then
    USEDTXT=`$DF -P $Partition 2>&1`
        #echo "USEDTXT value is $USEDTXT"
else
    USEDTXT=`$DF -P -B 1 $Partition 2>&1`
fi

#if [ $? != 0 ]
#then
#        echo "Error! Disk partition $Partition can't be checked. Does it exist?"
#        exit 3
#fi

if [[ $OS == AIX ]]; then
        CAPACITY=$(df "$Partition" | awk '!/Filesystem/ { print $4 }' | sed 's/%//')
#               echo "CAPACITY is $CAPACITY"
else
        CAPACITY=$(df -h "$Partition" | awk '!/Filesystem/ { print $4 }' | sed 's/%//')
fi


SpaceTxt=`echo "$USEDTXT" | $GREP "${Partition}\$"`
SpaceTotal=`echo "$SpaceTxt" | $AWK '{print $2}'`
SpaceUsed=`echo "$SpaceTxt" | $AWK '{print $3}'`
SpaceFree=`echo "$SpaceTxt" | $AWK '{print $4}'`
SpaceUsedProc=`echo "$SpaceTxt" | $AWK '{printf "%.1f", $3*100/$2}'`

SpaceFreeProc=`echo "$SpaceTxt" | $AWK '{printf "%.1f", $4*100/$2}'`

WarnSpaceAbs=`echo "$SpaceTotal $WarnSpace" | $AWK '{printf "%d", $1*$2/100}'`
CritSpaceAbs=`echo "$SpaceTotal $CritSpace" | $AWK '{printf "%d", $1*$2/100}'`
#echo "SpaceTxt value is $SpaceTxt"
#echo "SpaceTotal value is $SpaceTotal"
#echo "SpaceUsed value is $SpaceUsed"
#echo "SpaceFree value is $SpaceFree"
#echo "SpaceUsedProc value is $SpaceUsedProc"

if [[ $OS == AIX ]]; then
    SpaceTotal_F=`UNIX_btokmgt $SpaceTotal`
    SpaceUsed_F=`UNIX_btokmgt $SpaceUsed`
    SpaceFree_F=`UNIX_btokmgt $SpaceFree`
#       echo "SpaceTotal_F is $SpaceTotal_F"
#       echo "SpaceUsed_F is $SpaceUsed_F"
#       echo "SpaceFree_F is $SpaceFree_F"
else
    SpaceTotal_F=`btokmgt $SpaceTotal`
    SpaceUsed_F=`btokmgt $SpaceUsed`
    SpaceFree_F=`btokmgt $SpaceFree`
fi

PerfData="'used space'=${SpaceUsed}B;${WarnSpaceAbs};${CritSpaceAbs};0;${SpaceTotal} 'used space (pct.)'=${SpaceUsedProc}%;${WarnSpace};${CritSpace};0;100"
#echo "PerfData is $PerfData"
WarnSpace=$1
CritSpace=$2
CRITICAL_CONDITION=95
WARNING_CONDITION=90




if [[ $CritSpace < $CAPACITY ]]; then
    PS_STATUS="'$Partition' is at ${CAPACITY}% capacity, total ${SpaceTotal_F}, used ${SpaceUsed_F} (${SpaceUsedProc}%), free ${SpaceFree_F} (${SpaceFreeProc}%) | $PerfData"
    RESULT="CRITICAL"
    RETURN_STATUS=$STATE_CRITICAL
    FINAL_STATUS="$RESULT: ${PS_STATUS}"
    echo $FINAL_STATUS
    exit $RETURN_STATUS
elif [[ $WarnSpace < $CAPACITY ]]; then
    PS_STATUS="'$Partition' is at ${CAPACITY}% capacity, total ${SpaceTotal_F}, used ${SpaceUsed_F} (${SpaceUsedProc}%), free ${SpaceFree_F} (${SpaceFreeProc}%) | $PerfData"
    RESULT="WARNING"
    RETURN_STATUS=$STATE_WARNING
    FINAL_STATUS="$RESULT: ${PS_STATUS}"
    echo $FINAL_STATUS
    exit $RETURN_STATUS
else
    PS_STATUS="'$Partition' is at ${CAPACITY}% capacity, total ${SpaceTotal_F}, used ${SpaceUsed_F} (${SpaceUsedProc}%), free ${SpaceFree_F} (${SpaceFreeProc}%) | $PerfData"
    RESULT="OK"
    RETURN_STATUS=$STATE_OK
    FINAL_STATUS="$RESULT: ${PS_STATUS}"
    echo $FINAL_STATUS
    exit $RETURN_STATUS
fi

echo $FINAL_STATUS
exit $RETURN_STATUS

Please help me.
Thanks.

Last edited by rbatte1; 01-17-2017 at 08:19 AM.. Reason: Added CODE tags for error output
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

0403-057 Syntax error at line 70. pls help

Hi All, I got a script from one of the unix forums for reporting on filesystem usage and wanted to use it but it keeps giving me the following error. 0403-057 Syntax error at line 70 The script is shown below. Pls help as I am new to UNIX. # set -x # D I S K S P A C E . S H # #... (2 Replies)
Discussion started by: OMONI
2 Replies

2. Shell Programming and Scripting

get_source[34]: 0403-057 Syntax error at line 66 : `"' is not matched.

Hi, I am getting this error in my shell script, kindly help as soon as possible: ################################################################### # Main body of program ################################################################### . /saptech/scripts/common/declare # Defines... (1 Reply)
Discussion started by: vishal_ranjan
1 Replies

3. Shell Programming and Scripting

0403-057 Syntax error at line 52 : `)' is not expected.

Can someone please tell me wht is wrong with the following peice of code? I keep getting the following error - 0403-057 Syntax error at line 52 : `)' is not expected. case "${option_count}" in 1) java -Xms256m -Xmx1536m "${APPLNAME}" "${ACTION_TYPE}" > "${LOGFILE}" 2>... (2 Replies)
Discussion started by: Veenak15
2 Replies

4. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

5. Shell Programming and Scripting

ksh: 0403-057 Syntax error: `done' is not expected.

Hi I am getting error 'ksh: 0403-057 Syntax error: `done' is not expected.' when running below script any one can provide inputs on this. ------------------------ if then echo "Report Name |Modification Date|Report File Size|Owner" >SOX_`date +'%Y%m%d'` while read line do... (2 Replies)
Discussion started by: karnatis
2 Replies

6. Shell Programming and Scripting

0403-057 Syntax error

I am getting the error : rocfm/wls_subload/in/processed_files/tel_input_additional_checked_all_mandatory.txt: 0403-057 Syntax error at line 1 : `|' is not expected. >>>>ALL MANDATORY FIELDS CHECKING IS SUCCESSFUL count is 0 ... (3 Replies)
Discussion started by: princetd001
3 Replies

7. Shell Programming and Scripting

0403-057 Syntax error at line 169 : `"' is not matched.

Hi, I am getting this error in my attached shell script, kindly help as soon as possible: Thanks, Andre (2 Replies)
Discussion started by: damoon
2 Replies

8. Shell Programming and Scripting

0403-057 Syntax error at line : `}' is not expected.

i dont know where m i mistaking.. please help me out with this issue :( thanks in advance:rolleyes: one_main() { a=100 while ; do clear echo "##############################################" echo ":: CURRENTLY YOU ARE IN RC AND OC MARKING ::" echo... (1 Reply)
Discussion started by: Puneet sinha
1 Replies

9. AIX

0403-057 Syntax error at line 17 : `(' is not expected.

Hi, I am new to shell scripting.i am trying to mail after my backup completed. Here is my shell script: if ; then egrep (ERROR|error|Error|RMAN-) ${/backup/RMANBKUP/spool/shelltest.log} > /dev/null if ; then RESULT_MSG=WARNING: Errors occurred during the ${ORACLE_SID} Rman... (3 Replies)
Discussion started by: faruqms
3 Replies

10. Shell Programming and Scripting

0403-057 Syntax error at line 399 : `"' is not matched

Hi Everyone, I am getting strange behavior, same script runs fine without any error in one AIX machine, whereas on another it is throwing this error "0403-057 Syntax error at line 399 : `"' is not matched", I also ran the script in debug mode. This is the output, still doesn't say anything.... (2 Replies)
Discussion started by: sid1987
2 Replies
All times are GMT -4. The time now is 08:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy