LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-03-2003, 09:42 PM   #1
random_acts
LQ Newbie
 
Registered: May 2003
Posts: 2

Rep: Reputation: 0
Question sendmail does not work with cron?


Okay I have a perl script that checks the status of a dynamic ip address on my home network. If the address is changed, it makes a few changes in a couple of files and sends an email off to my work email. The script works fine when I run it from the command line directly, the files are changed, and the email is sent. The problem happens when I schedule it as a cron job. The script runs, the files are changed, but the email never gets sent. I run the job under root. There doesn't seem to be an error, because I don't get an email in my root mail box, but I also don't get an email in my work box.

Any ideas?

I am using
RH 9
Sendmail 8.12
I schedule the job through KCron

Last edited by random_acts; 05-03-2003 at 10:04 PM.
 
Old 05-04-2003, 07:21 AM   #2
mlp68
Member
 
Registered: Jun 2002
Location: NY
Distribution: Gentoo,RH
Posts: 333

Rep: Reputation: 40
Each time I have a "works in the shell, but not from cron" problem, I find that there is some difference in the env. settings that causes it. Add a printenv to the cron script and -v to the shell and compare the printenv output to what you have interactively. cron is not a login shell.

Hope it helps,
m
 
Old 05-04-2003, 12:18 PM   #3
random_acts
LQ Newbie
 
Registered: May 2003
Posts: 2

Original Poster
Rep: Reputation: 0
Right on the head.
The Cron PATH variable didn't include /usr/sbin/ where sendmail is, so I made some changes to my script and voila.

Thanks, I'm still new at this linux stuff.
It has taken me two whole days to figure this out!

tc
 
Old 04-16-2011, 02:51 AM   #4
BurninLeo
LQ Newbie
 
Registered: Apr 2011
Posts: 1

Rep: Reputation: 0
Thumbs up

Wow - this posting on sendmail and cronjobs is still helpful after 8 years
Thanks!
 
Old 12-15-2013, 05:16 AM   #5
seendds
LQ Newbie
 
Registered: Dec 2013
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by BurninLeo View Post
Wow - this posting on sendmail and cronjobs is still helpful after 8 years
Thanks!
After 10 years!
 
Old 04-18-2014, 03:47 PM   #6
grongor
LQ Newbie
 
Registered: Apr 2014
Posts: 1

Rep: Reputation: Disabled
Guess what, lol! Thanks again.
 
Old 05-08-2014, 09:11 AM   #7
Roberto70
LQ Newbie
 
Registered: May 2014
Posts: 1

Rep: Reputation: Disabled
Great, works for me too.
 
Old 05-08-2014, 10:25 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Good to know that not that much has changed in Linux in years, isn't it?
 
Old 05-12-2015, 10:04 AM   #9
chasse
LQ Newbie
 
Registered: May 2015
Posts: 1

Rep: Reputation: Disabled
Smile

Thank you!!! 12 Years
 
Old 07-21-2015, 01:31 AM   #10
fanuestro
LQ Newbie
 
Registered: Jul 2015
Location: Manila, Philippines
Distribution: CentOS 6.6
Posts: 1

Rep: Reputation: Disabled
after 12 years, this still works. Thanks!
 
Old 04-05-2020, 02:01 PM   #11
MatMercer
LQ Newbie
 
Registered: Apr 2020
Posts: 1

Rep: Reputation: Disabled
Well, 2020, and it solves the problem.

Using /usr/sbin/sendmail works like a charm.
 
Old 04-10-2021, 08:37 PM   #12
anuranjanverma
LQ Newbie
 
Registered: Apr 2021
Posts: 3

Rep: Reputation: Disabled
Issue still persists

I tried many solutions but none of them worked. I am using the below code in my crontabs. Not sure what I'm doing wrong but email is still not sending. However, when I open the webpage in the browser then I'm receiving the emails. Thank you!

PATH=/usr/sbin/sendmail
*/5 * * * * php /var/www/html/order-management/abc.php
*/15 * * * * php /var/www/html/order-management/def.php
*/5 * * * * php /var/www/html/order-management/email.php

My first two cronjobs are working fine where I'm inserting data inside the database. However, the last isn't where I'm sending email using sendmail
 
Old 04-11-2021, 07:39 AM   #13
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
PATH consists of directories!
Code:
PATH=/bin:/usr/bin:/usr/sbin:/sbin
*/5 * * * * php /var/www/html/order-management/abc.php
*/15 * * * * php /var/www/html/order-management/def.php
Or per command
Code:
*/5 * * * * PATH=$PATH:/usr/sbin php /var/www/html/order-management/abc.php
*/15 * * * * PATH=$PATH:/usr/sbin php /var/www/html/order-management/def.php
 
Old 04-12-2021, 06:59 AM   #14
anuranjanverma
LQ Newbie
 
Registered: Apr 2021
Posts: 3

Rep: Reputation: Disabled
Still not working

Thank you for your update. This is one of the first solution I'd already tried but didn't work.

Do you have any other solution? Just FYI, I am using Amazon Linux 2. Thanks!

Last edited by anuranjanverma; 04-12-2021 at 07:02 AM. Reason: forgot to mention Linux version
 
Old 04-12-2021, 12:39 PM   #15
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by random_acts View Post
Right on the head.
The Cron PATH variable didn't include /usr/sbin/ where sendmail is, so I made some changes to my script and voila.

Thanks, I'm still new at this linux stuff.
It has taken me two whole days to figure this out!

tc
This is the reason that it is strongly suggested that full paths to commands are used in scripts. It helps avoid $PATH issues.
 
  


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
cron and sendmail are eating my hard disk longtex Linux - Software 3 10-05-2005 01:34 PM
scp does not work with cron jobs yogendrarawat Linux - Newbie 2 09-15-2005 02:34 AM
Ssh Doesn't Work With Cron ? guano2 Linux - Networking 4 08-06-2005 12:57 AM
nmap with cron does not seem to work Gnarg Linux - Software 2 08-04-2004 10:05 AM
script runs fine from a command line, but doesn't work from cron? kleptophobiac Linux - Software 5 05-03-2004 04:14 PM

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

All times are GMT -5. The time now is 07:53 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
Open Source Consulting | Domain Registration