即使文件file1和file2不为空,我也不知道为什么我的脚本始终执行最后一个语句:
SERVER_NAME=$HOSTNAME
SENDER="Admin"
SUBJECT="Notification from "$SERVER_NAME""
RECEIVER="admin@mycompany.com"
file1=/home/first_file.txt
file2=/home/second_file.txt
TEXT1="The file $file1 is empty"
TEXT2="The file $file2 is empty"
TEXT3="Both files are empty"
if [ -s $file1 && -s $file2 ]
then
echo "files are good"
elif [[ -s $file1 ]]
then
echo -e "$TEXT2" | mail -s "$SUBJECT" "$RECEIVER" &>/dev/null
elif [[ -s $file2 ]]
then
echo -e "$TEXT1" | mail -s "$SUBJECT" "$RECEIVER" &>/dev/null
else
echo -e "$TEXT3" | mail -s "$SUBJECT" "$RECEIVER" &>/dev/null
fi
要求是在一个或两个文件为空的情况下发送通知
答案 0 :(得分:-1)
这是一个可供参考的工作脚本。
SERVER_NAME=$HOSTNAME
SENDER="Admin"
SUBJECT="Notification from "$SERVER_NAME""
RECEIVER="admin@mycompany.com"
file1=/home/first_file.txt
file2=/home/second_file.txt
TEXT1="The file $file1 is empty"
TEXT2="The file $file2 is empty"
TEXT3="Both files are empty"
if [[ -s $file1 && -s $file2 ]]
then
echo "files are good"
elif [[ -s $file1 ]]
then
echo -e "$TEXT2" | mail -s "$SUBJECT" "$RECEIVER" &>/dev/null
elif [[ -s $file2 ]]
then
echo -e "$TEXT1" | mail -s "$SUBJECT" "$RECEIVER" &>/dev/null
else
echo -e "$TEXT3" | mail -s "$SUBJECT" "$RECEIVER" &>/dev/null
fi