如果 wget 失败,请发送电子邮件
Send an email if wget fails
我正在编写一个脚本,它从 url 中获取一些重要数据(通过 cronjob)并在失败时发送电子邮件,但是,它似乎无法识别它是否失败( checking wget's return value [if]):
wget_output=$(wget --tries=1 --timeout=300 -r -N -nd -np --reject=html https://myurl/ -P ../data)
if [ $? -ne 0 ]
then
echo "send email here" >> ./test.txt
else
echo "send email here" >> ./test2.txt
fi
它只尝试了 1 次(按照说明)然后就放弃了,但不承认它是否成功。我假设我没有正确处理退出代码或其他东西。任何的想法?谢谢
您使用的 wget
是什么版本? 1.15 版手册页的退出状态部分说:
In versions of Wget prior to 1.12, Wget's exit status tended to be unhelpful and inconsistent. Recursive downloads would virtually always return 0 (success), regardless of any issues encountered, and non-recursive fetches only returned the status corresponding to the most recently-attempted download.
我正在编写一个脚本,它从 url 中获取一些重要数据(通过 cronjob)并在失败时发送电子邮件,但是,它似乎无法识别它是否失败( checking wget's return value [if]):
wget_output=$(wget --tries=1 --timeout=300 -r -N -nd -np --reject=html https://myurl/ -P ../data)
if [ $? -ne 0 ]
then
echo "send email here" >> ./test.txt
else
echo "send email here" >> ./test2.txt
fi
它只尝试了 1 次(按照说明)然后就放弃了,但不承认它是否成功。我假设我没有正确处理退出代码或其他东西。任何的想法?谢谢
您使用的 wget
是什么版本? 1.15 版手册页的退出状态部分说:
In versions of Wget prior to 1.12, Wget's exit status tended to be unhelpful and inconsistent. Recursive downloads would virtually always return 0 (success), regardless of any issues encountered, and non-recursive fetches only returned the status corresponding to the most recently-attempted download.