cron job not running as root

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?
Who is Participating?
SimpleJoeConnect With a Mentor Author Commented:
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

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.
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.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

actually since you can edit cron ignore the allow deny statement
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
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
SimpleJoeAuthor Commented:
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:


i'm checking the mail logs...
SimpleJoeAuthor Commented:
I verified from the logs that the email sends when run from the shell, but not when run as a root cron.

any ideas?

Please post the complete sendmail command as issued from the script!
SimpleJoeAuthor Commented:

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.
are you getting errors in the logs when the email doesn't send? Are your email variables sourced?

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?
SimpleJoeAuthor Commented:
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
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 => '',
   Subject => 'message',
   Data => 'Message body'


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

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?
open (LOGFILE,">>/home/chat8/public_html/ftp-mon/client/ftp-mon.log") || die "Error opening file for appending: $!";
To: $sendto_email
From: $sender_email
Subject: FTP update

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

Open in new window

SimpleJoeAuthor Commented:
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
SimpleJoeAuthor Commented:

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.