Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax-error [ : : integer expression needed 1

Status
Not open for further replies.

gosuc2000

Technical User
Jun 2, 2004
59
DE
hello ,

I'm not very good in scripts, but I'm getting nowhere even after reading all sort of infos concerning my script-problem.

I have a script, that queries a remote-system via ssh with "df -k". From that answer, I need to compare the returned value against a warning - and a critical threshold- supplied by parameters $3 and $4.
Thats the problem: (excerpt):

#!/bin/bash

#$1= remote IP
#$2= disk-name
#$3= warning-threshold
#$4= critical threshold
#$answ= return-message

if [ $# -ne 4 ]
then
echo "usage: "$0" <IP-Addr> <Disk-Name> <warn-thresh> <crit-thresh>

fi

free=`ssh -l root $1 df -k|grep $2|awk '{ print $ 5}'|cut -d "%" -f 1 -

used=`expr 100-$free`

>> following my line 23, complained in the err-mesage:<<
if [ "$3" -gt "$used" ]
then
answ="$used"
status=0
fi
.. Rest of code follows .....

Here, like with the rest of similar tests, I get the error:
expr: syntax error
./<prog-name>: line 23: [ : : integer expression expected.

But $3 as well as $used contain numbers.

Perhaps this is a good laugh for experts, but I have no idea how to solve this.

Any help is apreciated.

regards,

Fred.
 
I think that some lines from your script have been truncated when you posted because there are some missing end-quotes. Anyway, you need to remove this space...

free=`ssh -l root $1 df -k|grep $2|awk '{ print $[highlight] [/highlight]5}'|cut -d "%" -f 1 -

... and insert some spaces here (or consider using shell arithmetic instead of the expr command)...

used=`expr 100[highlight] [/highlight]-[highlight] [/highlight]$free`

 
Yeah..... , it finally works !!

You're right!

The problem was in the awk -part. After inserting a space in awk '{ print $5 }' to awk '{ print $ 5 }' it worked.

I always kept looking at the " if [ .. test " - part.
Well, that's experience.

Thank's a lot, you really helped me to finnish my job!

Regards,

Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top