0

I do not want to use Cloudwatch want to use shell script for this , Could you please suggest?

Actually i have written a script as below:

But its not alerting me when the EFS is unmounted.

#!/bin/bash
Hostname=$(hostname)
##email subject
subject="EFS is unmounted"
## sending mail to
to="santoshgarole5992@gmail.com"
## send carbon copy to
also_to="santoshgarole5992@gmail.com"

## Check if EFS is mounted or not
efscommenpart=$(df -kh | grep amazonaws.com | cut -d "." -f4)

## If EFS is unmounted
if [[ "$efscommenpart" -ne amazonaws  ]]

then

        echo -e "EFS is not mounted" | mailx -s "$subject" -r "$Hostname" -c "$to" "$also_to"
fi

This is urgent...!!!

0

As the bash scripting guide will tell you, -ne does integer comparison. To compare strings, you'll need to use the != operator instead.

Example:

$ var=empty
$ if [[ $var != "amazonews" ]]; then echo Send Email; else echo All Good; fi
Send Email

$ var=amazonews
$ if [[ $var != "amazonews" ]]; then echo Send Email; else echo All Good; fi
All Good

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.