LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-14-2006, 02:39 AM   #1
G00fy
Member
 
Registered: Jul 2004
Location: Herent, Belgium, Europe, Earth
Distribution: Ubuntu 7.04
Posts: 102

Rep: Reputation: 15
[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
But like 80% of the time the result is empty... So is the mail I get... How can I change this so that I only receive non-empty mails?


Thanks!
 
Old 09-14-2006, 01:07 PM   #2
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
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.
 
Old 09-14-2006, 03:22 PM   #3
G00fy
Member
 
Registered: Jul 2004
Location: Herent, Belgium, Europe, Earth
Distribution: Ubuntu 7.04
Posts: 102

Original Poster
Rep: Reputation: 15
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
 
Old 09-14-2006, 06:43 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,239

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
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
 
Old 09-19-2006, 05:29 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
cron already mails a file only when non-empty?

you don't need to mail the result to yourself.
 
Old 09-20-2006, 01:16 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,239

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
I suspect the OP is trying to email a 'remote user' ie not the local user acct that is actully running the cron job.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emailing Four LQ Suggestions & Feedback 3 02-24-2006 09:09 PM
Emailing, easy one this steve007 Linux - Newbie 2 08-01-2005 05:27 AM
Gentoo VNC, empty dialog box !! "Question" window is empty ! TheHushedCaskeT Linux - Software 0 02-01-2005 10:14 PM
apt-get install results : non empty dir | and strange site eeried Linux - Newbie 0 06-16-2004 03:34 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM


All times are GMT -5. The time now is 02:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration