You are not logged in.

#1 2012-02-29 10:26:34

SKull
Member
From: CH
Registered: 2009-11-11
Posts: 2

question regarding command substitution

hello folks

I wrote a simple nagios plugin which checks if mysql backup from the current date is available.
I pretty noobish in bash scripting and i just don't see the error

here's my script:

 21 DATE=$(date '+%y-%m-%d')
 22 STRING="*$DATE*"
 23 COMMAND=`find . -name $STRING`
 24
 25 if [ echo "$COMMAND" | grep -q "$DATE" ]; then
 26   echo "OK - Backup files found"
 27   exit 0
 28 else
 29   echo "Critical - No Backups found today!"
 30   exit 2
 31 fi

As you can see, nothing special. When i execute it i get the following error:

./find.sh: line 25: [: missing `]'
grep: ]: No such file or directory

i KNOW this has to be some kind of pretty stupid error but i just don't see it. Anyone that can help me?
greetings

Offline

#2 2012-02-29 10:29:10

portix
Member
Registered: 2009-01-13
Posts: 757

Re: question regarding command substitution

You can remove the brackets:

if echo "$COMMAND" | grep -q "$DATE"; then

Offline

#3 2012-02-29 10:35:06

SKull
Member
From: CH
Registered: 2009-11-11
Posts: 2

Re: question regarding command substitution

Thank you very much!

Offline

#4 2012-02-29 15:49:28

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: question regarding command substitution

#!/bin/bash

DATE=$(date '+%y-%m-%d')

if find | grep -q $DATE ; then
  echo "OK - Backup files found"
  exit 0
else
  echo "Critical - No Backups found today!"
  exit 2
fi

should work too and it's a bit shorter.



Please remember to mark the thread as solved.

Offline

Board footer

Powered by FluxBB