开发者

How to run command in the background and notify me via email when done

I have the following command which will take ages to run (couple of hours). I would 开发者_开发知识库like to make it a background process and for it to send me an email when its done.

For the cherry on the top, any errors it encountered should write to a text file when an error has occurred?

find . -type f -name "*.rm" -exec ./rm2mp3.sh \{} \; -exec rm \{} \;

How can I do this with my above command?


yourcommand 2>&1 | mail -s "yourcommand is done" yourname@example.com

The 2>&1 bit says "make my errors like the regular output", and the rest says "take the regular output and mail it to me with a nice subject line"

Note that it doesn't work in csh family of shells, only Bourne (sh, bash, ksh...), AFAIK. Thus, run under #!/bin/sh or #!/bin/bash. (N.B. You can pipe both descriptors in csh using yourcommand |& mail ..., but only a madman writes scripts using csh.)

UPDATE:

How would I write the errors to a log file and then just email my self on completion?

if you mean just email the fact that it is done,

yourcommand 1>/dev/null 2>mylogfile ; (echo "done!" | mail -s "yourcommand is done")

if you mean just email the errors (in which case you don't need the log file) (fixed as @Trey said),

yourcommand 2&>1 1>/dev/null | mail -s "yourcommand is done" yourname@example.com
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜