0

I'm receiving the following error when running a script:

line 6: [: : integer expression expected

I would imagine that the code inside the parenthesis is an integer, however, I can't see where it's going wrong. Please could you tell me how to fix this?

if [ "$( df -h | grep hda1 | cut -c40-42)" -ge "80" ]; then 
  echo Subject: Production Server : Low Disk Space : Daily reporting for Server
fi
0

4 Answers 4

1
if [ "$( df -h | grep hda1 | tr -s ' '|cut -d" " -f 5 | cut -c-2)" -ge 80 ]; then echo Subject: Production Server : Low Disk Space : Daily reporting for Server

If you trying to check the % used. I guess, this will be a better way to implement.

Sign up to request clarification or add additional context in comments.

4 Comments

why "if" before "df"?
aah.. typo.. sorry.. fixing it
I can't undo my downvote unless you edit your answer again
@glennjackman: edited. You can undo the downvote now..
1

df -h gives "human readable" output, like 1G or 73M. These obviously aren't integers. Try leaving out the -h. You might have to adjust your cut spacing to match.

Comments

1

A lot of pipes going on...

df -h | awk '/hda1/{sub(/%/,"")}$5>80'

Will work just as well as cut|grep|cut|tr without the added overhead

Comments

0

This one works fine for me:

[[ $(df -h | grep hda1 | cut -c40-42) -ge 80 ]]

I edited your question, you were missing the fi, was that a typo or is it an error?

1 Comment

typo; it's on the next line

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.