Results 1 to 2 of 2

Thread: Problem with a cron script

  1. #1
    Join Date
    Aug 2003
    Sydney, Australia

    Problem with a cron script

    Hi All,

    This has me utterly mystified. I have a cron that runs a php script. It used to work... now it doesn't, and nothing's been done to it. There are two parts to this problem... the cron and the script.

    Here's the cron...
    */10 * * * * root cd /usr/share/cms; /usr/bin/php5 /usr/share/cms/cron/cronsendmail.php > /var/log/cms/cronmail.log >/dev/null 2>&1

    The way I read that, every ten minutes, the Apache server,acting as root, runs a script called cronsendmail.php and any output ought to be written to cronmail.log.

    It certainly runs, because if I delete cronmail.log, ten minutes later, it's back. The problem is, it's an empty file.

    Therefore, I'm guessing the problem lies within the script. I'll post the entire script below... I've looked over it dozens of times and I can not see any error.

    PHP Code:
    //max emails per session
    $maxe 50;

    //set up the date
    $dte date("Y-m-d"time());
    $dx explode("-",$dte);
    $sqldate $dx[0]."-".$dx[1]."-".$dx[2];//yyyy-mm-dd

    //connect to master
    $mlink = @mysql_connect("localhost""user""password"TRUE) or die("Couldn't connect : ".mysql_error());
    mysql_select_db('filename'$mlink) or die("Couldn't open filename : ".mysql_error());
    // I've sanitised user, password and filename, or course... they are correct in the running version.
    $qrl "INSERT INTO filename.syslog (type) VALUES ('mailcronst')";
    $rsl mysql_query($qrl);

    //get the mailer function

    //get next 50 unsent mail
    $qrm "SELECT * FROM filename.mailqueue WHERE MQsent = 'N' ORDER BY MQdate ASC LIMIT ".$maxe;
    $rsm mysql_query($qrm$mlink);
    $rwm mysql_fetch_array($rsm))
    $rn $rwm['MQrn'];
    $xto $rwm['MQto'];
    $xtoname $rwm['MQtoname'];
    $xfrom $rwm['MQfrom'];
    $xfromname $rwm['MQfromname'];
    $xsubject $rwm['MQsubject'];
    $xitem $rwm['MQmailitem'];
    $xmaildomain $rwm['MQdomain'];
    $xpassword $rwm['MQpassword'];
    $xtype $rwm['MQtype'];

    $sm explode("@",$xfrom);
    $smtp "mail.".$sm[1];

    $xheaders "Subject: " $xsubject "\r\n";
    $xheaders .= "To: ".$xto."\r\n";
    $xfromname==""){$xheaders .= "From: ".$xfrom."\r\n";}else{$xheaders .= "From: ".$xfromname." <" $xfrom ">\r\n";}
    $xheaders .= "Return-Path: ".$xfrom."\r\n";
    $xheaders .= "MIME-Version: 1.0\r\n";
    $xheaders .= "Content-Type: ".$xtype."; charset=ISO-8859-1\r\n";

    "SENDING VIA SMTP<br/>";
    $qrl "INSERT INTO filename.maillog (MLdate, MLdomain, MLto, MLsubject) VALUES ('$sqldate', '$xmaildomain', '$xto', '$xsubject')";
    $rsl mysql_query($qrl$mlink);
    //delete the mail
    $qrd "DELETE FROM filename.mailqueue WHERE MQrn = '$rn'";
    $rsd mysql_query($qrd$mlink);
                else    if(
    $qrl "INSERT INTO filename.maillog (MLdate, MLdomain, MLto, MLsubject) VALUES ('$sqldate', '$xmaildomain', '$xto', '$xsubject')";
    $rsl mysql_query($qrl$mlink);
    //delete the mail
    $qrd "DELETE FROM filename.mailqueue WHERE MQrn = '$rn'";
    $rsd mysql_query($qrd$mlink);
    "SENDING VIA MAIL<br/>";
    $qrl "INSERT INTO filename.maillog (MLdate, MLdomain, MLto, MLsubject) VALUES ('$sqldate', '$xmaildomain', '$xto', '$xsubject')";
    $rsl mysql_query($qrl$mlink);
    //delete the mail
    $qrd "DELETE FROM filename.mailqueue WHERE MQrn = '$rn'";
    $rsd mysql_query($qrd$mlink);
    $qrl "INSERT INTO filename.syslog (type) VALUES ('mailcronfn')";
    $rsl mysql_query($qrl);
    The general idea is that when the CMS sends an email, it stores it in a file for sending in batches. I can then send via smtp rather than php's mail() function.

    This cron is supposed to connect to the database where the batched mails are filed, check the file, send the email, then delete them from the file after recording the outgoing mail in a maillog file.

    It then writes a simple record in syslog to tell me it's done.

    To recap... when the cron runs, I get a file opened as var/log/cms/cronmail.log. That file is empty, and nothing has been touched in the database.

    I thought it might be something to do with the error settings in my php.ini file, so I added error_reporting(E_ALL); to the top of the script... no difference.

    I then thought I'd just try commenting out everything except print "Done!" at the end... no difference... still a blank file.

    Finally, I tried it without the 'filename.' in the sql... no difference.

    This is driving me nuts and I would be most appreciative if someone might be able to point me in the right direction.

    Oh Lord, please help me be the person my dog thinks I am.

  2. #2
    Join Date
    Aug 2004
    What happens if you comment out the second redirection in the cron job?
    */10 * * * * root cd /usr/share/cms; /usr/bin/php5 /usr/share/cms/cron/cronsendmail.php > /var/log/cms/cronmail.log #>/dev/null 2>&1
    (Hoping you'll at least see some debug info in the .log file.)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09459 seconds
  • Memory Usage 2,903KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates