JP Vossen on 7 Nov 2007 03:51:07 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Auto-send Email


> Date: Tue, 06 Nov 2007 20:05:22 -0500
> From: Eugene Smiley <eug+plug@esmiley.net>
>
> Corrected /dev/null.

Bad habit of mine. I started out on DOS, which uses NUL, and I can never remember which is what. So I type /dev/nu{tab} and use whatever I get. In this case I happened to be on a Debian box that has both /dev/nul and /dev/null. But my Gutsy box only has the more canonical /dev/null, which I should have used. Sorry...


> Added an rm -f to delete the file only after sending since it won't > be needed again. > > Final result: > auto_send=`{ ls -t autosendfile* | tail -n1; } 2> /dev/null` > [ "$auto_send" ] && cat "$auto_send" | mail -e -s 'Autosend' list; \ > rm -f "$auto_send"

WARNING: that will delete the file whether the 'mail' part works or not!!! I'd use this so we only delete if everything worked (lines broken for email):
[ "$auto_send" ] && cat "$auto_send" \
| mail -e -s 'Autosend' list \
&& rm -f "$auto_send"


Note a trivial style point above. When I have to break lines, I like to put the operator at the beginning of the line rather than leave it on the end of the preceding line. IMO that makes it much more obvious not only that you're continuing a broken line, but what you're doing. I also indent a bit. Compare the snippet above with this, which I consider much less readable:
[ "$auto_send" ] && cat "$auto_send" | \
mail -e -s 'Autosend' list && \
rm -f "$auto_send"



> Works brilliantly. Thanks. And my brain thanks you.

Happy to help.
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|        jp{at}jpsdomain{dot}org
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
Microsoft has single-handedly nullified Moore's Law.
Innate design flaws of Windows make a personal firewall, anti-virus
and anti-malware software mandatory. The resulting software arms race
has effectively flattened Moore's Law on hardware running Windows.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug