Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cron Mystery



I'm am out of ideas, I can't figure out why my cron job won't run...

Here's the details...

This is running on an Intel RH7 machine...

Simple cron job that is suppose to send out a mailing to people in a database...

I can run the perl script from the command line as root, and it does exactly what it is suppose to, which is read from a MySQL database, pull out the email addresses and send off an email to each one...
The job is listed in root's crontab...
I put in some simple print statements throughout the script, and the entire script is getting executed, both when I run it from the command line AND when it runs from the cron - I know what your thinking, didn't he say it's NOT working?!?!?
The catch is that it doesn't do the mailing part (which is the reason the script is running)...

I've put the script below in case I'm missing something simple...

Thanks in advance,
Phil

# Imports
use DBI;
use MwfConfig;
use MwfLanguage;
use MwfMain;

eval "use $cfg{'createEmailMod'}" if $cfg{'createEmailMod'};

#------------------------------------------------------------------------------

# Don't run this from CGI
!$ENV{'GATEWAY_INTERFACE'} || $ENV{'MWF_ALLOWCRON'} or die "No CGI execution";

# Do nothing if subscriptions are disabled
$cfg{'subscriptions'} or exit;

# Call external handler in MwfSendEmailExt if defined, and exit
subscriptionsExt(), exit if defined(&subscriptionsExt);

# Connect database
connectDb();

# Get last sent time
my $lastSentTime = getOption("crnSubLst") || 0;

# Get boards
my $query = "SELECT * FROM boards";
my $sth = query($query);
my $boards = $sth->fetchall_arrayref({});
my $addresses;

# Intro text with URL
my $body = "Below you will find a link to the iConsult Team Room, as well as a list of the topics posted to the board yesterday. If you haven't yet, we encourage you to take advantage of the Team Room to share (and learn) consulting information and best practices from your colleagues.\n\nNOTE:  If you do not want to receive daily iConsult Team Room batch e-mails, you may select \"Do not receive batch email.\" in the User Profile section of the Team Room.\n--------------------------------------------------\n";
$body .= "$cfg{'forumName'} ($cfg{'baseUrl'}$cfg{'cgiPath'}/forum.pl)\n\n"

# Go through boards
for my $board (@$boards) {
        # Get posts
        $query = "
                SELECT subject, userName, postTime, body
                FROM boards, posts, topics, users
                WHERE boards.id = $board->{'id'}
                        AND posts.boardId = $board->{'id'}
                        AND topics.id = topicId
                        AND users.id = userId
                        AND postTime > $lastSentTime
                        AND (NOT boards.approve OR posts.approved)
                ORDER BY topicId, postTime";
        $sth = query($query);
        my $posts = $sth->fetchall_arrayref({});
        next unless @$posts;

        # Moving this up above the for statement since we are squishing all the
        # board emails into one giant email ...
        # Intro text with URL
        #$body = "$cfg{'forumName'} ($cfg{'baseUrl'}$cfg{'cgiPath'}/forum.pl)\n"
        #       . "$lng{'subSubject'} '$board->{'title'}'"
        #       . "\n\n--------------------------------------------------\n\n";

        # Copy all post bodies together
        for my $post (@$posts) {
                dbToEmail($board, $post);
                my $timeStr = formatTime($post->{'postTime'});
                $body .= "BOARD:$board->{'title'} - $lng{'subTopic'}: $post->{'subject'}\n";
                $body .= "$lng{'subBy'}: $post->{'userName'}\n";
                $body .= "$lng{'subOn'}: $timeStr\n\n";
                $body .= $post->{'body'};
                $body .= "\n\n--------------------------------------------------\n\n";
        }

        # Assemble subject
        my $subject = "$cfg{'forumName'} - $lng{'subSubject'} '$board->{'title'}'";

        # Get recipients
        $query = "
                SELECT email
                FROM users, subscriptions
                WHERE users.id = userId
                        AND boardId = $board->{'id'}";
        $sth = query($query);
        $addresses = $sth->fetchall_arrayref();
        next unless @$addresses;
}
        # Send emails
        my $subject = "iConsult Team Room - Yesterday's Posts";
        for my $address (@$addresses) {
                sendEmail({'to' => $address->[0], 'subject' => $subject, 'body' => $body});
        }
#}

# Set last sent time
setOption("crnSubLst", time(), 0);

# Disconnect DB
$dbh->disconnect() or die "Subscriptions: Disconnect failed.";

1;

-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org