我有一个问题,关于一个脚本,我发现了监控设备在我的网络。
剧本:
#!/bin/bash
HOSTS="192.168.11.1"
COUNT=1
SUBJECT="Ping failed"
EMAILID="me@mydomain.com"
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID
fi
done在执行脚本时,它似乎正常工作,但它不会将任何内容发送到电子邮件地址。有人能告诉我我做错了什么吗?
发布于 2014-05-08 19:24:27
按以下方式编辑脚本,然后再试一次。
#!/bin/bash
HOSTS="192.168.11.1"
COUNT=1
SUBJECT="Ping failed"
EMAILID="me@mydomain.com"
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
cd ~
if [ -s PING_FILE ]
then
rm PING_FILE
fi
echo "Host : $myHost is down (ping failed) at $(date)" > PING_FILE
mail -s "$SUBJECT" $EMAILID < PING_FILE
#if you want to get the file itself use the below code #
mutt -s "$SUBJECT" -a PING_FILE - $EMAILID < PING_FILE
fi
done致以敬意,
多米尼克
https://stackoverflow.com/questions/23550451
复制相似问题