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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 0403-057 Syntax error at line 17 : `(' is not expected.
# 1  
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
# 2  
Old 01-17-2017
Should this line:
Code:
             echo "$1" | $AWK '{printf "%.1fTB",($1*512)/1099511627776}'

actually be this line:
Code:
             echo "$1" | $AWK '{printf "%.1fTB", ($1*512)/1099511627776}'

This would match the other similar lines close by.


If not, then can you run the script with the -x option set and track down the line better that way?



Robin
# 3  
Old 01-17-2017
I can't see anything obvious neither near line 17 (as in the thread title) nor around line 55 (as in the error message). Please do as already proposed and post the (xtrace) context of/around the error.
# 4  
Old 01-17-2017
Hi.

Does this demonstration help?
Code:
#!/usr/bin/env ksh

# @(#) s1       Demonstrate forms for function definition.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
em() { pe "$*" >&2 ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C
pe

function a {
  echo " From a"
  return
}

b() {
  echo " From b"
  return
}

function c() {
  echo " From c"
  return
}

a
b
c

exit

producing:
Code:
$ ./s1 

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie) 
ksh 93u+

./s1: line 21: syntax error at line 26: `(' unexpected

Best wishes ,,, cheers, drl
This User Gave Thanks to drl For This Post:
# 5  
Old 01-18-2017
To clarify a bit what drl showed in his example:

in ksh the syntax is either
Code:
function foo {
  bar
}

Which is ksh style function, or
Code:
foo () {
  bar
}

which is a posix style function
But:
Code:
function foo() {
  bar
}

is a syntax error
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 01-18-2017
Thanks,

Issue has been Sorted.
SmilieSmilie
# 7  
Old 01-18-2017
Hi.

I was lucky in spotting the issue, and noticed after the first post that one could also use shellcheck. The heart of this solution, after listing the context, environment, and input shell script to be analyzed, is simply shellcheck <filename>:
Code:
#!/usr/bin/env bash

# @(#) s2       Demonstrate shellcheck.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
em() { pe "$*" >&2 ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C shellcheck

FILE=${1-s1}

pl " Input data file $FILE:"
cat $FILE

pl " Results:"
shellcheck $FILE

exit 0

producing:
Code:
$ ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie) 
bash GNU bash 4.3.30
ShellCheck - shell script analysis tool

-----
 Input data file s1:
#!/usr/bin/env ksh

# @(#) s1       Demonstrate forms for function definition.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
em() { pe "$*" >&2 ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f "$C" ] && . "$C"
pe

function a {
  echo " From a"
  return
}

b() {
  echo " From b"
  return
}

function c() {
  echo " From c"
  return
}

a
b
c

exit 0

-----
 Results:

In s1 line 26:
function c() {
^-- SC2111: ksh does not allow 'function' keyword and '()' at the same time.

Some details on shellcheck:
Code:
shellcheck      analyse shell scripts (man)
Path    : /usr/bin/shellcheck
Version : ShellCheck - shell script analysis tool
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with -h
Repo    : Debian 8.6 (jessie) 
Home    : http://hackage.haskell.org/package/ShellCheck

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question