我有一个 shell 脚本,它会定期检查 ADSL 外部 IP 地址,并在它发生更改时将其发送到我的电子邮件。
#! /bin/sh
NEWIP=`/usr/bin/curl ifconfig.me`
OLDIP=`cat ./current`
logger "$NEWIP ... $OLDIP"
if [ "$NEWIP" != "$OLDIP" ]; then
TIME=`/bin/date`
/usr/bin/sendEmail -v -f ip_watcher@xxxoo.com \
-s smtp.gmail.com:587 -xu ip_watcher@xxxoo.com -xp xxxxxx \
-t xxx@xxxxx.com \
-o tls=yes \
-u "$NEWIP" \
-m "$NEWIP $TIME" -a
/bin/echo "$NEWIP" > ./current
logger "IP of bjserver1 has changed ..."
else
logger "New IP is the SAME with old. not sending ..."
fi
当我从命令行运行它时,这非常有效。但是我把它放入cron之后,NEWIP和OLDIP总是一样的。我不知道为什么,有人可以帮忙吗?