IF question

Hi there

I'm new to bash and unix for that matters. Just started yesterday, having to do a script for work, outputting HTML from various system info's. And me having coded Rexx for years ... then this is a little different :slight_smile:

My question is simple .... I have an IF that does not work - > It seems to run the commmand instead.

I need to set a variable after a given percentage ...

Can you give me a hint.

regards
Mette

---------------------------------------------

while read inputline
do
   
   filsyst="$(echo $inputline | awk '{print $2}')"
       pct="$(echo $inputline | awk '{print $6}')"
   
   if ["$pct" >= $DiskCritical]; then
      BGC='FF0000'
   else 
      if ["$pct" >= $DiskWarning]; then
         BGC='EEDD11' 
      else
         BGC='009900'
      fi
   fi
   
   ... bla bla HTML stuff    
done < $limit

This is the content of the file:

/ /dev/mapper/VolGroup00-LogVol00 38471112 9755264 26730108 27%
/boot /dev/hda1 101086 12043 83824 13%
/dev/shm tmpfs 546000 286688 259312 53%
/media/VBOXADDITIONS_3.2.4_62467 /dev/hdc 32686 32686 0 100%

Could you, please, post some of those "input lines", or, even better, the whole "limit file"?

I've added the info in the original question above now :slight_smile: (It's basicaly just output from a -df -kP)

I also have a q uestion on how to format a number - ie 3.750,55 as a result of dividing a number with 1024 (diskspace calcs).

I can find lots of fun stuff - but the very basic I cant seem to find.

Regards
Mette

try this :wink:

pct="$(echo $inputline | awk '{print $6}' | sed 's/.$//' )"

and

if (( "$pct" >= $DiskCritical ))
1 Like

Hi

Thank you very much - works like a charm.

Where is the best place to learn the basic stuffs about scripting?
I dont do much work on the Unix/Linux machine in my daily work, but I have to develop some generic scripts for monitoring and sending status HTML stuff back to the customers.

regards
Mette

I can advise for learning
Advanced Bash-Scripting Guide

and unix.com forums :slight_smile:

Works fine on the Linux box, but on the AIX (think it is 3.5) box the IF fails with:

./unix_test.sh[16]: >= 90 : 0403-057 Syntax error

Its because of an "empty" field (null) compares to 90 ..

I need it to run on Solaris, HP_UX, Linux, True64 etc, so I was hoping that only the commands (ie vmstat, date, df etc) were different.

Can you offer help again?

regards
Mette

can you write complete of your script

One way is to add a 0 tot the variable to do the integer test if the pct could be an empty string:

pct="$(echo $inputline | awk '{sub(".$","",$6); print $6 + 0}')"

if (( "$pct" >= $DiskCritical ))

BTW: I've do the substitition of sed within the awk command and this test instruction could be more portable:

if [ "$pct" -ge "$DiskCritical" ]

add a control give error if pct is null

if [[ "$pct" = "" ]] ; then pct=0; echo $pct; fi