Bash 输出问题

Bash 输出问题

我有以下脚本:

/bin/sh
echo  "Compare Ran" $(date) >> /var/log/ran.log
if cmp -s "/var/log/ip.log" "/etc/wanip.log"
then
   echo "Wan Check Ran" | /var/log/ran.log
else
   echo "WARNING IP CHANGE" | sendmail *********@email.****.net
fi

如果这两个文件不匹配,则脚本可以正常工作,但如果这两个文件匹配,我会得到以下输出:

/var/log/ran.log: 1: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 2: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 3: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 4: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 5: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 6: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 7: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 8: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 9: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 10: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 11: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 12: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 13: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 14: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 15: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 16: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 17: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 18: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 19: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 20: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 21: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 22: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 23: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 24: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 25: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 26: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 27: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 28: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 29: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 30: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 31: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 32: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 33: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 34: /var/log/ran.log: Thu: not found
/var/log/ran.log: 35: /var/log/ran.log: Compare: not found
/var/log/ran.log: 36: /var/log/ran.log: Compare: not found
/var/log/ran.log: 37: /var/log/ran.log: wanip.sh: not found
/var/log/ran.log: 38: /var/log/ran.log: Compare: not found

如果这两个文件相同,我无论如何也想不通为什么脚本似乎在“读取”ran.log 文件。

有任何想法吗?

答案1

这行代码试图将“/var/log/ran.log”作为脚本执行

echo "Wan Check Ran" | /var/log/ran.log

虽然我相信你想将字符串“Wan Check Ran”添加到日志中。因此你应该

echo "Wan Check Ran" >> /var/log/ran.log

相关内容