LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-14-2011, 03:38 PM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
cron job running but not getting the email that should send


Hi all,

i am using a crontab to run a perl script.
When i check the /var/log/cron, it shows that cron job ran successfully but i am not getting the output that the script should send. The same script runs successfully on a solaris server and sends output as email. Is there any other place to look for possible causes. Thanks in advance!

Code:
# crontab -l
00 07 * * * /usr/local/test/cron.d/report.pl > /dev/null 2>&1

#more /var/log/cron |grep report.pl
Jul 14 07:00:01 linux001 crond[21018]: (root) CMD (/usr/local/test/cron.d/report.pl > /dev/null 2>&1)

# ps -ef|grep cron
root      2675     1  0 Jan18 ?        00:00:05 crond
root      7475  6524  0 15:31 pts/0    00:00:00 grep cron
root     26588  2675  0 Jul13 ?        00:00:00 crond

Last edited by linuxandtsm; 07-14-2011 at 03:40 PM.
 
Old 07-14-2011, 04:15 PM   #2
brian-ocs
LQ Newbie
 
Registered: Jul 2011
Location: San Diego, CA
Distribution: CentOS 6, Linux Mint Debian Edition
Posts: 18

Rep: Reputation: 1
Quote:
00 07 * * * /usr/local/test/cron.d/report.pl > /dev/null 2>&1
Piping standard output and standard error to /dev/null probably isn't necessary, depending on what mechanism the script uses to generate the email message. You might try eliminating the "> /dev/null 2>&1" from the cron job and/or including this "silencing" function within the script itself.

It's hard to say without seeing the script, but my guess is that this is dumping the script's email output to /dev/null or some other critical output the script generates while executing.

It also might be an issue with your mail client. Does mail work for everything else?
 
Old 07-14-2011, 04:27 PM   #3
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi brian-ocs,

I am afraid to post the script as it is having 2986 lines.
I am hoping that the script should be good as it was working fine on another server.
Yes, the mail client working fine as i am getting other emails from other cronjobs.
 
Old 07-14-2011, 06:53 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Well, redirect stdout & stderr to a file (instead of /dev/null) and see what you get in it. Also note that cron generally emails either the cron job owner or root if it has a problem.

Also, given this is Perl, have you tried
Code:
perl -wc report.pl
to check that it can find all the Perl modules referenced.
(That cmd does a Perl 'compile' & syntax check without executing the program. )

Last edited by chrism01; 07-14-2011 at 06:56 PM.
 
1 members found this post helpful.
Old 07-15-2011, 09:32 AM   #5
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Thank you Very much chrism01,

owner of the cronjob is root.
Yes, redirecting output to a file showed that the script is executing successfully and giving the desired output.
The only problem is, it somehow not sending this output as an email.

BTW:
Code:
# perl -wc report.pl
report.pl syntax OK
 
Old 07-15-2011, 09:41 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Can you post the lines of the script that should be sending the mail and any associated "log" output?
 
Old 07-15-2011, 10:12 AM   #7
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
This
Code:
..... > /dev/null 2>&1
prevents any output generated from cron to be sent to email.
Remove it and it should send an email with output.

I have this part of the code at the end of "ntpdate .... " line in cron when NTP syncs the time and I don't want to receive emails about executing it!
 
Old 07-15-2011, 10:23 AM   #8
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi catkin,

The following are some sections in the script related email.

Code:
our %output = (
               report_email => 1,                      # Send the report in email?
               report_stdout => 0,                     # Output it to stdout?
               report_txtsave => 1,                    # Save it in a text file?
              );



# If you set report_email above then change this section.
our %email = (
              recipients => 'myemail.mycompany.com', # <- Who gets the email report?  
             
              mailhost => '',                            # <- If we don't have sendmail installed, what
                                                         #  SMTP host should we use.  If you want to
                                                         #  use your system's sendmail set this to
                                                         #  ''.  Setting this option requires the
                                                         #  Net::SMTP module.
                          );


# Send the report in email.
#
sub email_report {
  my ( $self, $mailfrom, $mailto, $mailhost, $compress_attachments ) = @_;



# -> email
if( $output{report_email} ) {
  $R->attach_file( "actlog.txt", join("\n",@actlog_raw) ) if $email{attach_actlog};
  $R->attach_file( "serious_errrors.txt", join("\n",@errors) ) if $email{attach_data_errors};
  $R->attach_file( $tsm{drmdir}."/".$tsm{drmfile} )
    if( $email{attach_drm_plan} and  defined $tsm{drmfile} and -f  $tsm{drmdir}."/".$tsm{drmfile} );
  if( $email{attach_scripts} ) {
    my $S = "


$R->email_report( $email{sender}, $email{recipients}, $email{mailhost}, $email{compress_attachments} );
BTW what "log" should i be looking at ?

@lithos,

Yes i tried removing > /dev/null 2>&1 but no luck. Not getting emailed.
 
Old 07-15-2011, 11:20 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by linuxandtsm View Post
BTW what "log" should i be looking at ?
The "log" which was the file in "Yes, redirecting output to a file showed that the script is executing successfully and giving the desired output".
 
Old 07-15-2011, 11:54 AM   #10
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
The output contains 1542 lines and it is all about the results of commands used in the script.
Is there any way to know what are the emails sent by the server like to whom,when,subject etc ?
 
Old 07-16-2011, 03:10 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by linuxandtsm View Post
The output contains 1542 lines and it is all about the results of commands used in the script.
Is there any way to know what are the emails sent by the server like to whom,when,subject etc ?
Not without some familiarity with the perl script's output/logging functionality or examining the code's flow, looking for parts that generate output and finding the corresponding lines in the output/log.

I'm no perl-spert, was just helping move the thread along by asking the right questions, but this looks wrong unless you have changed it to hide confidential information:
Code:
recipients => 'myemail.mycompany.com'
 
Old 07-19-2011, 10:39 AM   #12
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Code:
I'm no perl-spert, was just helping move the thread along by asking the right questions, but this looks wrong unless you have changed it to hide confidential information
Yes, i changed it to hide the info.
 
Old 07-19-2011, 01:51 PM   #13
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi all,

Now i know that redirecting the script's output to a file shows that script is running fine.
Now is there a way to modify cronjob so that it can send the output file to my email .
like
Code:
00 07 * * * /usr/local/test/cron.d/report.pl > /output.txt
...then what should be added to this cron job to send output.txt as email (not as an email attachment)

Thanks in advance!
 
Old 07-19-2011, 06:13 PM   #14
Nermal
Member
 
Registered: Jan 2009
Distribution: Debian
Posts: 59
Blog Entries: 2

Rep: Reputation: 6
Code:
00 07 * * * /usr/local/test/cron.d/report.pl
this will e-mail root and if you have redirected the root mail to you it will arrive.
 
Old 07-19-2011, 06:41 PM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
If you just run it from the cmd line interactively, does it email you?
If yes, the its an env problem in cron; if no, its a general env /programming problem & you'll need to read the code/output to discover what.

Re cron env, try 'perl -wc report.pl' in cron; redirect the stdout+stderr to a file as previously advised.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make root cron job to send email if there is output mirror51 Linux - Newbie 3 08-12-2009 02:01 AM
cron job to send file via ftp every 1 hour mcalizo Linux - Newbie 1 07-14-2004 04:50 AM
usin AWK in cron job to send dynamic ip via email digihlp Programming 2 12-10-2003 09:10 AM
Cron job , send email mikeshn Linux - General 1 09-21-2003 10:02 AM
Send Email + Txt Attachment Using Cron Job beringer Linux - Newbie 3 01-31-2003 11:23 AM


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