CiviMail, wget and Cron Annoyances

Wget can be really annoying... how can you completely suppress all possible output when running wget as a cron job.

PROBLEM
If you run CiviMail to check for outgoing mail every 10 minutres and you have many sites on a server, you can quickly fill your home directory with thousands of empty files creating a file descriptor problem if ignored for long enough. :)

See also the drupal module 'poormanscron' to take care of othe Drupal side of things. You will still need a 'real' CiviMail cronjob as it does not have poormanscron hooks.

SOLUTION
Use the '--spider' option with /dev/null output shell redirection to cover every possible condition

CiviMail cron job example on Dreamhost VPS. (all one line) Same for any cron job:

wget --spider --force-html 'http://yourdomain.com/sites/all/modules/civicrm/bin/civimail.cronjob.php?name=name&pass=password&key=key'>/dev/null 2>&1

Make sure you have a minimally privileged cron user in Drupal to allow the cron process access to the CiviCRM mailer. For CiviCRM 3 you need a site key.

Enjoy!

DRUPAL & CRON

Here's some more useful cron trivia.

This is just a quick caveat (or reminder). If you delete a variable from the variables table, always clear the cached entry of the variables too. Drupal caches the whole variables table in the cache table in an entry called 'variables'.

Here are two cases (of the many) you'll need this.

When you're writing your own module and you're setting some variables, always clean them up. Fastest way is by issuing a direct query to the database.

/**

 * Implementation of hook_uninstall().

 */


function my_module_uninstall() {

  db_query("DELETE FROM {variable} WHERE name LIKE 'my_module_%'");

  cache_clear_all('variables', 'cache');

}

A second typical case I can come up with is when releasing the cron semaphore after it got 'stuck'.

DELETE FROM variable WHERE name = 'cron_semaphore';

DELETE FROM cache WHERE cid = 'variables';