LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-28-2013, 04:13 AM   #1
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 539

Rep: Reputation: 33
A question about send mail in script


Hi,

I have a script as cronjob as follow:
Code:
#!/bin/bash

SUBJECT="This is a test"

result=$(find /var/log/jboss-apps/test -type f -size +10k)

#echo RESULT=$result

if [[ -z $result ]]; then
  echo NULL
else
  echo RESULT=$result
  $result | mail -s $SUBJECT my.name@mycom.com
fi
What I want to do is:
I will check if any file size greater than 10k every 10 min., assumed,.

But to my strange the email is send to the following addresse:

my.name@mycom.com; a@mycom.com; is@mycom.com; test@mycom.com;

Seems the SUBJECT is broken to as email addresses.

And the result is not send as contents.

Why?
 
Old 10-28-2013, 04:42 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Shouldn't that be:
Code:
echo "$result" | mail -s "$SUBJECT" my.name@mycom.com
Also mind the double quotes.
 
Old 10-28-2013, 05:10 AM   #3
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 539

Original Poster
Rep: Reputation: 33
I also noticed the double quotes and change as follow:

Code:
...
RECEIVER="my.name@mycom.com"
...

if [[ -z $result ]]; then
  echo NULL
else
  echo RESULT=$result
  "$result" | mail -s "$SUBJECT" "$RECEIVER"
fi
...
Now the email is just sent to one email address "my.name@mycom.com". But I can't see the contents though it must be not NULL.

And as I run this script I got:

Code:
RESULT=/var/log/jboss-apps/test/server.log.2013-10-24
./check-file-size: line 17: /var/log/jboss-apps/test/server.log.2013-10-24: Permission denied
Null message body; hope that's ok
The line 17 is: "$result" | mail -s "$SUBJECT" "$RECEIVER"

Last edited by thomas2004ch; 10-28-2013 at 05:15 AM.
 
Old 10-28-2013, 05:17 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
OK let's try again

Code:
echo "$result" | mail -s "$SUBJECT" "$RECEIVER"
and not
Code:
"$result" | mail -s "$SUBJECT" "$RECEIVER"
 
1 members found this post helpful.
Old 10-28-2013, 05:28 AM   #5
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 539

Original Poster
Rep: Reputation: 33
bingo!!!

Many thanks!
 
  


Reply



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
[SOLVED] How to send a mail using shell script gajananh999 Linux - Newbie 2 11-29-2012 01:55 AM
How to send mail through script ramecare Linux - Server 13 05-10-2011 11:44 AM
Using 'mail' in a script to send mail on an alternate port? tim914 Linux - Software 4 01-16-2009 03:23 PM
Send mail through script aabfm Linux - Networking 5 07-01-2006 04:46 AM
CGI Script runs to send mail, but mail is never sent robertwo Linux - Newbie 2 06-10-2004 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:33 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration