I want to refer with this question to the following post where I got the Skript: Post with Script
I'm using Bash 4.1.2(1) and when I try to execute the script, I get following error messages:
./check_disk_by_size.sh: Zeile 9: [: ==: Einstelliger (unärer) Operator erwartet. (standard_in) 1: syntax error ./check_disk_by_size.sh: Zeile 13: [: -eq: Einstelliger (unärer) Operator erwartet. (standard_in) 1: syntax error (standard_in) 1: syntax error ./check_disk_by_size.sh: Zeile 16: [: Zu viele Argumente. (standard_in) 1: syntax error ./check_disk_by_size.sh: Zeile 19: [: -eq: Einstelliger (unärer) Operator erwartet.
I have basic Bash-scripting experiences but whenever I change something, I get even more errors. I'm not able to bring it to work.
EDIT 1: Here's the script
#!/bin/bash FREESPACE=`/usr/local/nagios/libexec/check_nt -H $2 -p 12489 -s PASSWORD \ -v USEDDISKSPACE -l $4 | awk -F"- " '{ print $4 }' | awk -F "|" '{ print $1 }'` SIZE=`echo $FREESPACE | awk '{ print $2 }'` UNIT=`echo $FREESPACE | awk '{ print $3 }'` if [ $UNIT == "Gb" ]; then SIZE=`echo $SIZE \* 1024 | bc` fi if [ `echo "$SIZE >= $6" | bc` -eq 1 ]; then echo "$4:\_Drive_Space OK - $FREESPACE" exit 0 elif [ `echo "$SIZE < $6" | bc` -eq 1 -a `echo "$SIZE > $8" | bc` -eq 1 ]; then echo "$4:\_Drive_Space WARNING - $FREESPACE" exit 1 elif [ `echo "$SIZE <= $8" | bc` -eq 1 ]; then echo "$4:\_Drive_Space CRITICAL - $FREESPACE" exit 2 fi
I run the script like this:
./check_disk_by_size -H [IP_Adress] -l [DRIVE] -w [INTEGER] -c [INTEGER] -p [PORT] -s [PASSWORD]
Example:
./check_disk_by_size -H 192.168.1.110 -l c -w 10240 -c 8192 -p 12489 -s PASSWORD
UPDATE
Thanks for your help! It works now :) The script looks like this now:
#!/bin/bash # FREESPACE=`/usr/local/nagios/libexec/check_nt -H $2 -p 12489 -s Nag4AlphA \ -v USEDDISKSPACE -l $4 | awk -F"- " '{ print $4 }' | awk -F "|" '{ print $1 }'` SIZE=`echo $FREESPACE | awk '{ print $2 }'` UNIT=`echo $FREESPACE | awk '{ print $3 }'` if [ "$UNIT" == "Gb" ]; then SIZE="$(echo "$(($SIZE * 1024))" | bc)" fi echo $SIZE echo " " echo $6 echo " " echo $8 if [ $SIZE -ge $6 ]; then echo "$4:\_Drive_Space OK - $FREESPACE" exit 0 elif [ $SIZE -lt $6 -a $SIZE -gt $8 ]; then echo "$4:\_Drive_Space WARNING - $FREESPACE" exit 1 elif [ $SIZE -lt $8 ]; then echo "$4:\_Drive_Space CRITICAL - $FREESPACE" exit 2 fi
#!/bin/bash
or#!/bin/sh
in your script?bash -x check_disk_by_size arguments
so you can have a small debug on how it is performing.