LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-23-2010, 06:18 AM   #1
msw1970
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Rep: Reputation: 0
Perl, Sendmail & Crontab


Hi

I have a perl script that includes a line to execute a system command that sends an email using sendmail... The line is

!system "sudo /usr/sbin/sendmail -t -f \"<vmlnx16.xxx.xxx\@xxx.co.uk>\" < /tmp/message.txt > /dev/null 2>&1 &" or die $!;

where the xxx represents the email address.

If I run the script manually then the email is sent. However, if I try to run the script through the following crontab line then the mail is not sent. The crontab line is..

30 2 * * * root /opt/bin/check-configs.pl > /dev/null/ 2>&1 &

I know that the script gets executed because the creation of other files such as the /tmp/message.txt used above happens. Also, I know that the script is not dieing at that point as commands after it in the script are executed.

Any ideas anyone??

Last edited by msw1970; 09-23-2010 at 06:20 AM.
 
Old 09-23-2010, 06:55 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by msw1970 View Post
Hi

I have a perl script that includes a line to execute a system command that sends an email using sendmail... The line is

!system "sudo /usr/sbin/sendmail -t -f \"<vmlnx16.xxx.xxx\@xxx.co.uk>\" < /tmp/message.txt > /dev/null 2>&1 &" or die $!;

where the xxx represents the email address.

If I run the script manually then the email is sent. However, if I try to run the script through the following crontab line then the mail is not sent. The crontab line is..

30 2 * * * root /opt/bin/check-configs.pl > /dev/null/ 2>&1 &

I know that the script gets executed because the creation of other files such as the /tmp/message.txt used above happens. Also, I know that the script is not dieing at that point as commands after it in the script are executed.

Any ideas anyone??
Why do you need 'sudo' ? Try to get rid of it first.
 
Old 09-24-2010, 03:05 AM   #3
msw1970
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Sergei Steshenko View Post
Why do you need 'sudo' ? Try to get rid of it first.
I'll give it a try without although I don't see that it will make a difference as the script executes fine from a command line, just not from crontab.
 
Old 09-25-2010, 12:04 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Probably the usual cron issue that the $PATH variable is different under cron than it is in a user shell. Either set up $PATH, or spell out the exact filespec of all executables (sudo, for one).
--- rod.
 
Old 09-25-2010, 12:23 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by theNbomr View Post
Probably the usual cron issue that the $PATH variable is different under cron than it is in a user shell. Either set up $PATH, or spell out the exact filespec of all executables (sudo, for one).
--- rod.
The OP invoked the command in question with full path: /usr/sbin/sendmail .
 
Old 09-25-2010, 12:49 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Yes, but he didn't didn't spell out the location of sudo (/usr/bin/sudo, on the host from which I write this).
--- rod
 
Old 09-25-2010, 01:05 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by theNbomr View Post
Yes, but he didn't didn't spell out the location of sudo (/usr/bin/sudo, on the host from which I write this).
--- rod
And that's one of the reasons I suggested to get rid of it. Another reason is that 'sudo' might refuse to run when it doesn't have a terminal.

I.e. 'sudo' looks like a dark horse here, and it's unneeded functionally.
 
  


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
RHEL4u2 perl localtime() call issues (perl & glibc) Brad.Scalio@noaa.gov Linux - Enterprise 3 01-23-2007 09:27 PM
crontab sendmail linuxhippy Slackware 13 07-24-2006 03:02 PM
sendmail is not working & on $prompt the cmd sendmail hangs Pavan mahoorker Linux - Software 1 04-04-2006 03:57 PM
making an entry in crontab through code (perl) akaash Programming 2 05-17-2004 03:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:48 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