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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
01-08-2014, 04:08 PM
|
#1
|
Member
Registered: Oct 2010
Posts: 606
Rep:
|
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?
|
|
|
01-08-2014, 04:12 PM
|
#2
|
Senior Member
Registered: Mar 2012
Posts: 1,882
|
Use full paths in your notify_eqsendmail.sh script.
|
|
1 members found this post helpful.
|
01-08-2014, 05:45 PM
|
#3
|
Member
Registered: Oct 2010
Posts: 606
Original Poster
Rep:
|
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?
|
|
|
01-08-2014, 06:05 PM
|
#4
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
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 06:06 PM.
|
|
1 members found this post helpful.
|
01-08-2014, 08:42 PM
|
#5
|
Member
Registered: Oct 2010
Posts: 606
Original Poster
Rep:
|
Quote:
Originally Posted by schneidz
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.
|
|
|
01-09-2014, 09:43 AM
|
#6
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,594
|
Quote:
Originally Posted by devUnix
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.
|
01-09-2014, 01:27 PM
|
#7
|
Member
Registered: Oct 2010
Posts: 606
Original Poster
Rep:
|
Quote:
Originally Posted by TB0ne
...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.
|
|
|
01-09-2014, 01:35 PM
|
#8
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
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.
|
01-09-2014, 01:50 PM
|
#9
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,594
|
Quote:
Originally Posted by devUnix
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?
|
|
|
01-09-2014, 01:55 PM
|
#10
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
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.
|
01-13-2014, 02:08 PM
|
#11
|
Member
Registered: Oct 2010
Posts: 606
Original Poster
Rep:
|
Quote:
Originally Posted by TB0ne
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.
|
|
|
01-13-2014, 02:28 PM
|
#12
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,594
|
Quote:
Originally Posted by devUnix
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?
|
|
|
01-13-2014, 02:40 PM
|
#13
|
Member
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262
Rep:
|
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.
|
01-13-2014, 03:31 PM
|
#14
|
Member
Registered: Oct 2010
Posts: 606
Original Poster
Rep:
|
Quote:
Originally Posted by TB0ne
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 03:33 PM.
|
|
1 members found this post helpful.
|
01-13-2014, 03:55 PM
|
#15
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,594
|
Quote:
Originally Posted by devUnix
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?
|
|
|
All times are GMT -5. The time now is 08:18 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|