我在 cron 作业中使用以下脚本来在 EFS 卸载时收到警报。
但卸载 EFS 时它不会提醒我。
#!/bin/bash
Hostname=$(hostname)
##email subject
subject="EFS is unmounted"
## sending mail to
to="[email protected]"
## send carbon copy to
also_to="[email protected]"
## 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
谁能建议我哪里做错了?
这很紧急...!!!
答案1
作为bash 脚本编写指南会告诉您,-ne
进行整数比较。要比较字符串,您需要使用!=
运算符。
例子:
$ 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