Solved

cron job not running as root

Posted on 2010-09-13
16
1,265 Views
Last Modified: 2013-11-08
Hi, this has stumped some techs. I'm on a cPanel server and added this root cron job entry using "crontab -e" --

0,15,30,45 * * * * perl /home/chat8/public_html/ftp-mon/client/ftp-mon.cgi

it runs fine when I run it from the command line, but it is not running as a
cron job every 15 minutes starting at the top of the hour as it should

I've edited other existing cron entries and that works, so I know crons are running and I know I'm editing the correct root cron file

any ideas?
0
Comment
Question by:SimpleJoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 3
  • +2
16 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33661990
Hi,
I think that perl is not in the standard path /usr/bin (maybe it's /usr/local/bin?)
Issue "which perl" as root and change the crontab enty accordingly, so if "which perl" would return "/usr/local/bin/perl" use
0,15,30,45 * * * * /usr/local/bin/perl /home/chat8/public_html/ftp-mon/client/ftp-mon.cgi
Also make sure that all variables are set inside ftp-mon.cgi , and that all executables are called by full path (if no PATH variable is being set inside the script).
This is because shell initialization profiles are not executed under cron.
wmp
 
0
 
LVL 11

Expert Comment

by:jgiordano
ID: 33662436
also check the /var/log/cron see if there are any errors

check that there are no cron.allow or cron.deny files and if there are make sure root is allowed.
0
 
LVL 11

Expert Comment

by:jgiordano
ID: 33662442
actually since you can edit cron ignore the allow deny statement
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 78

Expert Comment

by:arnold
ID: 33662873
The other item you should check is whether you have Setuid on the cgi and/or whether the CGI has a set effective owner/group.

As woolmilkproc pointed out, you may not be using full paths in the cgi script and the system commands you are trying to run might not be found

you can use env - to pass the PATH to the
i.e.
your cron entry:
0,15,30,45 * * * * perl /home/chat8/public_html/ftp-mon/client/ftp-mon.cgi
will be:
0,15,30,45 * * * * env PATH=/bin:/sbin:/usr/bin:/usr/local/bin:$PATH - /usr/bin/perl /home/chat8/public_html/ftp-mon/client/ftp-mon.cgi
0
 

Author Comment

by:SimpleJoe
ID: 33663077
ok I figured something out, it seems the cron is running as root, what's not happening is the script is supposed to send an email when done executing, it's just the email that's not being send.

even though the path is correct in the script:

/usr/sbin/sendmail

i'm checking the mail logs...
0
 

Author Comment

by:SimpleJoe
ID: 33663268
I verified from the logs that the email sends when run from the shell, but not when run as a root cron.

any ideas?

thanks,
Joe
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33663342
Please post the complete sendmail command as issued from the script!
0
 

Author Comment

by:SimpleJoe
ID: 33663726

variable defined:

$mailprog = "/usr/sbin/sendmail";


then later:

    # Open The Mail Program
    open(MAIL,"|$mailprog -t");
    print MAIL "To: $sendto_email\n";
    print MAIL "From: $sender_email\n";
    print MAIL "Subject: FTP update\n";
    print MAIL "A file was uploaded:\n\n";
    close (MAIL);


again, it works from the shell, not from cron job.
0
 
LVL 11

Expert Comment

by:jgiordano
ID: 33664324
are you getting errors in the logs when the email doesn't send? Are your email variables sourced?
0
 
LVL 78

Expert Comment

by:arnold
ID: 33664971

Are you certain the scripts when run from cron gets as far as generating the email?

Are there checks in the script that when failed, exit?
0
 

Author Comment

by:SimpleJoe
ID: 33666707
there is a command at the end of the script that I verified runs, nothing in email logs sent to the unique address I setup... will keep checking stuff
0
 
LVL 4

Expert Comment

by:rajendraone
ID: 33666966
Use perl module to better handle email. It is much more robust than using sendmail. Can easily send an attachment as well and easy to send html message as well.

use MIME::Lite;
my $message = MIME::Lite->new(
   To => 'user@example.org',
   Subject => 'message',
   Data => 'Message body'
);

$message->send();

If you don't have MIME::Lite module installed you will get error. If so try installing the module by issuing following command:
# cpan -i MIME::Lite


0
 
LVL 78

Expert Comment

by:arnold
ID: 33666983
Add the following above the Mail
just trying to see whether something goes wrong and the message is rejected.
The problem is that you are not checking whether open MAIL,"|$mailprog" actually worked.

Have you look at the emails on the system sent to root as the username under whose credentials the cron runs for error messages from cron when there was output or errors?
$date_example=localtime();
open (LOGFILE,">>/home/chat8/public_html/ftp-mon/client/ftp-mon.log") || die "Error opening file for appending: $!";
print LOGFILE <<EOF
To: $sendto_email
From: $sender_email
Subject: FTP update

A file was uploaded: $date_example
EOF
;
close (LOGFILE);

Open in new window

0
 

Author Comment

by:SimpleJoe
ID: 33684437
I tried the alternate mail method from rajendraone:, worked great from the shell but no email was sent from the cron.

In reply to arnold, I grepped the entire /var/log/* for the address it sends to, but  entries only appear when I run it from the command line, yet I know the cron job runs.

I'm beginning to think this is more related to a security setting in cron not allowing the sending of email (on a cpanel server)

will keep researching.... thanks
0
 

Author Comment

by:SimpleJoe
ID: 33684534

i changed it to a user's cron job instead of a root cron job, and it appears to maybe be working.

will post update when I know for sure
0
 

Accepted Solution

by:
SimpleJoe earned 0 total points
ID: 33684799
unexplicitly, now it's working from root.

perhaps setting it up as the user made some system change that kicked it into gear

it's working now. but I can't say for sure how, the last thing I did was setup a cron for the user

i since deleted the user cron and it's running, sending email and all, as root

 
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question