[crontab] emailing non-empty results
Hi all,
At the moment I do something like this: Code:
/bin/sh script.sh | mutt -s Result email@mail.be Thanks! |
You should output the results as /tmp/result.txt then attach them in the message. You should call mutt within the script.sh file at the bottom. You can specify to send result.txt if it is not empty with an 'if' function.
if [ -s /tmp/result.txt ]; then mutt -s "Result $(date +%F)" email@mail.be < /tmp/result.txt fi I recommend a good book on script writing for bash or perl. |
Thanks ramram29, but I was more thinking about some 1 liner. I know you can put all of this on 1 line in the crontab, but I have like 10 entries there mailing me stuff every hour, and about 90 others during the day...
So you can understand that I don't want to type so much, and I'm looking for an easy solution. Also it seems so rough to export to a file, which would need to be a default filename (bad idea ;), better to have random name then), which I just check if empty and remove it... Just doesn't feels good. Oh, and I have a good book lying here, it's just no use for what I need to do with it. I already found this kind of solution, but threw it away because of the reasons mentioned above. Thanks anyway :) |
In that case, either add a filter to your smtp server, or write a simple shell prog that you can insert in the pipelines eg
/path/script1.sh|your_filter.sh where your_filter.sh decides whether the inut requires emailing or not, and takes care of it. Incidentally, it's better to put the hash-bang line ( #!/bin/bash) at the top of each sh script and just call it without separately invoking the shell eg as per my example |
cron already mails a file only when non-empty?
you don't need to mail the result to yourself. |
I suspect the OP is trying to email a 'remote user' ie not the local user acct that is actully running the cron job.
|
All times are GMT -5. The time now is 06:14 AM. |