Where's my stderr going?
I have a bash script that includes the command:
mv old.txt new.txt
Old.txt doesn't exist, so when I run the script from the commandline, it gives me the message:
mv: cannot stat ``test1.txt': No such file or directory
If I call the script from cron, however, and try to redirect stderr and stdout to a log file, I end up with a completely blank log (this is done as root in this case, but I still have this problem when it's set in my user crontab).
Crontab entry:
# m h dom mon dow command
0 * * * * 开发者_如何学运维/home/beekguk/scripts/test.sh 2>&1 >> /home/beekguk/logs/test.log
So - where's stderr going in this case? Does it just disappear? I've seen on various forums that it gets mailed to root, but I'm not sure what that means or how to find it.
I know just enough about Linux and bash to get me in hot water, and I have a feeling this one may end up with me smacking my forehead and going "Doh!", but thought I'd give it a try anyway.
Edit: I got around this by correcting the redirection on my crontab entry:
0 * * * * /home/beekguk/scripts/test.sh >> /home/beekguk/logs/test.log 2>&1
... but I'm still curious about where these messages would go if I forgot to redirect them!
For anyone reading this in the future: note that I accepted the answer equally for the helpful comment thread.
You have your redirections reversed. Standard error is therefore going to the cron job's standard output, which is normally mailed to whoever owns the job.
精彩评论