LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-08-2014, 05:08 PM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
mail command not sending emails from within a script


Hi,


I have this case reported by a user.

There is a cronjob (placed under "/etc/cron.d/" directory) which sends emails:

Code:
30 13 * * 1-5 totem bash --login -c "/home/totem/scheduled-tasks/daily/notify_eqsendmail.sh 235 APAC > /dev/null 2>&1"
Mail line in script (variables already set up):

Code:
echo -e "$message $missingdata $message2 $message3" | mail -s "Daily Volume: Missing Data" $to -- -f $from

There is no log found in "/var/log/maillog" when the script finishes. That is no emails are sent.

I checked the log for the cron job which looks fine to me:

Code:
# grep '/home/totem/scheduled-tasks/daily/notify_eqsendmail.sh' /var/log/cron | tail -n 1
2014-01-08T21:30:02.239122+00:00 myhost001 crond[6135]: (totem) CMD (bash --login -c "/home/totem/scheduled-tasks/daily/notify_eqsendmail.sh 235 EMEA > /dev/null 2>&1")
When the script is run manually, the emails go fine.


What should I do next?
 
Old 01-08-2014, 05:12 PM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,640

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Use full paths in your notify_eqsendmail.sh script.
 
1 members found this post helpful.
Old 01-08-2014, 06:45 PM   #3
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
The paths to mail and sendmail are included in the PATH for the user. I think we can set the PATH in the crontab too?
 
Old 01-08-2014, 07:05 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,236

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
i think the $PATH variable gets set via .profile or .bash_profile when the user logs in. since the user is not logging in, the cron has no idea where the mail command is located.

Last edited by schneidz; 01-08-2014 at 07:06 PM.
 
1 members found this post helpful.
Old 01-08-2014, 09:42 PM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by schneidz View Post
i think the $PATH variable gets set via .profile or .bash_profile when the user logs in. since the user is not logging in, the cron has no idea where the mail command is located.
I had already set the PATH in a script under:

/etc/profile.d/

directory.

The cronjob has the option:

bash --login

which should say:

login and run the job/command.
 
Old 01-09-2014, 10:43 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 20,813

Rep: Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148
Quote:
Originally Posted by devUnix View Post
I had already set the PATH in a script under:

/etc/profile.d/ directory.

The cronjob has the option:

bash --login

which should say: login and run the job/command.
...and since you're not taking the advice you've been offered (that is, putting the full path in your script), why bother asking us for advice? Modify the script...it'll take a few seconds, and you can see if it works, rather that arguing with folks about why it SHOULD work (yet obviously ISN'T).
 
1 members found this post helpful.
Old 01-09-2014, 02:27 PM   #7
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by TB0ne View Post
...and since you're not taking the advice you've been offered (that is, putting the full path in your script), why bother asking us for advice? Modify the script...it'll take a few seconds, and you can see if it works, rather that arguing with folks about why it SHOULD work (yet obviously ISN'T).
That is one example given. The developers here have got several of them. Some are working and some are not. If I could hand-change the script(s) I would not bother posting my question here at all.
 
Old 01-09-2014, 02:35 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,236

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
for the one that isnt working can you add a line like this above where you call mail:
Code:
echo path = $PATH :: mail = `/usr/bin/which mail`
to make sure you are using the expected program.
 
1 members found this post helpful.
Old 01-09-2014, 02:50 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 20,813

Rep: Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148
Quote:
Originally Posted by devUnix View Post
That is one example given. The developers here have got several of them. Some are working and some are not. If I could hand-change the script(s) I would not bother posting my question here at all.
Then why didn't you tell us any of this at the very start? How many scripts are there, which ones aren't working, and what's common between them? And WHY can't you 'hand-change' them?
 
Old 01-09-2014, 02:55 PM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,236

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
can you sanitize (copy/paste) an example of one thats working and also one thats not working and annotate which user/system they are running from.
 
1 members found this post helpful.
Old 01-13-2014, 03:08 PM   #11
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by TB0ne View Post
Then why didn't you tell us any of this at the very start? How many scripts are there, which ones aren't working, and what's common between them? And WHY can't you 'hand-change' them?
TB0ne: -> I have learned a lot of things from you in the past. I request you to be calm down here.
 
Old 01-13-2014, 03:28 PM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 20,813

Rep: Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148
Quote:
Originally Posted by devUnix View Post
TB0ne: -> I have learned a lot of things from you in the past. I request you to be calm down here.
Nothing not 'calm' about my question..why can't you answer it, and why didn't you provide complete details at the very beginning?
 
Old 01-13-2014, 03:40 PM   #13
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
Instead of redirecting stdin and stderr to /dev/null, redirect it to a file. There's definitely error messages you're not seeing because of this.
 
1 members found this post helpful.
Old 01-13-2014, 04:31 PM   #14
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by TB0ne View Post
Nothing not 'calm' about my question..why can't you answer it, and why didn't you provide complete details at the very beginning?
The problem with you here is: you have many "why's" which may not occur to one's mind at first.

Now, to answer your question:

I can't hand-change the scripts because they are not owned by me or by my group.

Secondly, the dve team does not want changes in the original scripts otherwise they would have to go through CAB process again. That is their problem - not mine. So, I was looking for a suitable solution or workaround for them. However, they do not seem to understand your/my points. This raises a question on how different teams within in organisation should co-ordinate with one another.


One of my seniors here in the organisation told me that if there is something we are supposed to know and we don't know they "the blame" is on us. If there is something they are supposed to tell us in advance and we don't ask still "the blame" is on us. Even if there is something they should know/understand and they don't try to know or understand.... my good friend.... "the blame" is still on us.

Last edited by devUnix; 01-13-2014 at 04:33 PM.
 
1 members found this post helpful.
Old 01-13-2014, 04:55 PM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 20,813

Rep: Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148Reputation: 5148
Quote:
Originally Posted by devUnix View Post
The problem with you here is: you have many "why's" which may not occur to one's mind at first.
The "whys" are because you didn't provide the details when you asked the question. You mentioned ONE script, with ONE problem...then come back and say it's several scripts, which you can't change. Both of which are VERY relevant to getting an answer, which should have occurred to you when asking the initial question.
Quote:
Now, to answer your question:
...which you could have done without making comments previously.
Quote:
I can't hand-change the scripts because they are not owned by me or by my group.
...and if they're not your scripts, why are you maintaining/troubleshooting them?
Quote:
Secondly, the dve team does not want changes in the original scripts otherwise they would have to go through CAB process again. That is their problem - not mine. So, I was looking for a suitable solution or workaround for them. However, they do not seem to understand your/my points. This raises a question on how different teams within in organisation should co-ordinate with one another.
...which is nothing that anyone here can help with. If a script is broken, you have two choices: fix it or live with it. There isn't a third option. Putting workarounds in does nothing but make things a maintenance nightmare later. Migrate to a new system and copy the scripts?? Won't that be nice...since NONE OF THEM WILL WORK, without modifying system config files. Get a new guy in to write a script? They won't be able to write a 'standard' script...since the 'workarounds' will make things more complicated, and make anything you do further on worse to document. And (essentially) having one team responsible for part of a script, and another responsible for the rest is just asking for headaches.

You were given advice by schneidz, and I agree with it. CRON does not inherit such things, and if you think about it, you'd see why. You're using "-login"...great...now, since cron does not have a user ID, how would it inherit things like paths/etc from the login profiles? Cron is a daemon...which is why scripts need full path names in them.
Quote:
One of my seniors here in the organisation told me that if there is something we are supposed to know and we don't know they "the blame" is on us. If there is something they are supposed to tell us in advance and we don't ask still "the blame" is on us. Even if there is something they should know/understand and they don't try to know or understand.... my good friend.... "the blame" is still on us.
Not to sound harsh, but that's YOUR problem. There's nothing anyone here can do about the office politics at your company. If you don't like the policies at your company, pack up and get another job.

What we CAN address on this site is technical issues. The script is broken, and you say you're not allowed to fix it...so what's the point of the whole thread?
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail error 530 5.5.1 when sending emails badger_fruit Linux - Software 2 06-21-2013 11:18 AM
mail program sending multiple emails countrydj Linux - General 2 09-02-2011 12:24 PM
problems with From: header when sending emails from my domain using mail() function mavgh1 Linux - General 5 03-26-2006 03:48 PM
problems with From : header when sending emails with function mail() from my domain mavgh1 Linux - Software 0 03-24-2006 08:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration