JP Vossen on 6 Nov 2007 23:51:52 -0000 |
> Date: Tue, 06 Nov 2007 17:34:12 -0500 > From: Eugene Smiley <eug+plug@esmiley.net> From JP: >> How about this (untested) shell script in a cron job? >> >> #!/bin/sh - >> auto_send=`{ ls -t file_to_send* | tail -n1; } 2> /dev/nul` >> [ "$auto_send" ] && cat "$auto_send" | mailx -s 'Subject' user@example.com > > JP you are shameless. ;) Well, I said I was, didn't I? :-) > Thanks for the help. Right now all my books are in boxes ready to be > moved to Ft. Lauderdale next week. I may even HAVE that bash > book, but I'm not about to tear through a bunch of boxes to find it! Understandable.
Grab only the last (oldest) file using 'tail -n1', per your reqs.
Yup. Obviously, there are improvements that could be made. For example, check for existence of file_to_send* and continue only if one or more exist. Then don't ignore errors, so if something does go wrong you get a cron message about it. But it sounded like you wanted short, quick & dirty. The '{}' are just a way to group commands, but are slightly tricky in that they require surrounding white space and the tailing ';'. If you want to send the file as an attachment rather than as the message body, you can pipe it into uuencode (or other similar tool). That'll still put it in the body, and it will be about 33% larger, but most modern email clients will decode it as an attachment on the other end. Or you can use 'mutt -a "$auto_send"' (IIRC). This is covered in recipe 15.15 in the book. You can get the example code for free from the O'Reilly site, but there is little that isn't already above. :-) Good luck with the code and the move, 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
|
|