How to prevent emailed cron output

走远了吗. 提交于 2019-12-25 01:56:04

问题


I'm using a cron that gets accesses a URL to run a scheduled process. I keep getting successful emails... is there a way for me to only get emails if the wget request fails?

wget http://www.domain.com/cron/dailyEmail 2>&1;


回答1:


wget --quiet http://www.domain.com/cron/dailyEmail || echo "wget failed"

(Note that an empty response is not a failure.)




回答2:


If you're running wget directly in the cron setup, then no. You can't conditionally redirect output. You could, however, put the wget command into a shell script, and do the conditionals there.

#!/bin/sh

OUTPUT=`wget .... 2>1`
if [ $? != 0 ]
   echo $OUTPUT
fi


来源:https://stackoverflow.com/questions/7246850/how-to-prevent-emailed-cron-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!