PDA

View Full Version : error_log produced by cron job


mr_git
15th March 2006, 15:27
Hi,

I've got a couple of cron jobs running on my account which do a mysqldump of my databases and then e-mail the gzipped dump to a gmail account.

The dump and gzipping etc.. is done just with some shell commands, and then a PHP script runs which sends the gzipped file as an attachment to as e-mail.

It seems to be working fine, but every time the PHP script runs, the server is logging an error in a file called error_log in my home directory.

Here's an example of what the log says:


[15-Mar-2006 02:55:02] PHP Warning: Unknown(): Unable to load dynamic library './/usr/local/lib/php/extensions/ixed/ixed.4.4.lin' - .//usr/local/lib/php/exte
nsions/ixed/ixed.4.4.lin: cannot open shared object file: No such file or directory in Unknown on line 0


From a little googling on ixed.4.4.lin, it looks like this relates to something called sourceguardian, but other than that, I'm not too sure what's going on.

Could anyone shed any light on this? I'd ideally like the cron job to be running without buildling up an error log.

cheers,
mr_git

Steve
15th March 2006, 17:28
Hello,

That's strange - does your script that is ran on the cronjob use SourceGuardian at all?


Regards,

mr_git
15th March 2006, 17:39
Hi Steve,

yes it is odd - no my script doesn't have anything to do with SourceGuardian; it's very simple in fact, just reading the gzipped file into a variable, and then encoding up a MIME e-mail, and sending it.

I'll not post the actual script here just now, but can do later (with my personal data obscured) if it would help.

cheers,
Drew.

Steve
15th March 2006, 18:44
Hi Drew,

I'll not post the actual script here just now, but can do later (with my personal data obscured) if it would help.
Yeah, that should help. :) Does it create entries in your error_log if it's called normally via a web browser?


Regards,

mr_git
15th March 2006, 20:13
Here's the script:


<?php
/* php script to be run by cron
which sends a file (e.g. a database dump)
as an attachment to an e-mail.

mcdruid.co.uk 2006

the following is a suggested entry to put in the crontab
set to run shortly before this script:

mysqldump -uUSERNAME -pPASSWORD --all-databases > ~/backups/daily_db_backup.sql ; gzip -f -9 ~/backups/daily_db_backup.sql

*/

// config variables
$account_name = "my_account"; //the *nix username of this account on the server
$target_email = "my_email@gmail.com"; //the e-mail to send this file to (gmail recommended for capacity if nothing else!)
$filename = "daily_db_backup.sql.gz"; //the file to send

// some derived settings - check that these look sensible
$path = "/home/$account_name/backups/";
$reply_to_email = "cron_$account_name@my_domain.co.uk";
$comments = "cron : $account_name : $filename";

// unique boundary (for use in the MIME e-mail)
$boundary = md5(uniqid(time));

// if the file exists, get it ready for the e-mail
if (file_exists($path. $filename))
{
// get contents of the file to be sent into a string
$size_of_file = filesize($path. $filename);
$handle = fopen($path. $filename, "rb");
$backup_file = fread($handle, $size_of_file);
fclose($handle);

$size_of_file_in_kb = round($size_of_file/1000); //see http://en.wikipedia.org/wiki/Kilobyte
$comments .=" (". $size_of_file_in_kb. "kb)";

//generate the (MIME) attachment for the e-mail
$attachment = "--$boundary\n" .
"Content-Type: application/x-gzip\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$filename}\"\n" .
"Content-Transfer-Encoding: base64\n\n";
$attachment .= chunk_split(base64_encode("$backup_file"));

}
else
{
// doesn't look like the file is there - so send a notification e-mail instead
$comments .= "[**FAILED**] file not found";
$attachent = ""; //no file to attach
}

// set up the headers for the MIME e-mail
$headers .= "X-Mailer: php\n";
$headers .= "From: cron:$account_name <$reply_to_email>";
// n.b. I use GMT - replace gmdate with just date if you just want server time
$mail_sent_date = gmdate("l jS F Y", time());
$message = "Sent on: $mail_sent_date\r\n$comments";
$plain_text = $message;

// specify MIME version 1.0
$headers .= "MIME-Version: 1.0\n";

// tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\n\n";

// message to people with clients who don't understand MIME
$headers .= "This is a MIME encoded message.\n\n";

//plain text version of message
$headers .= "--$boundary\n" .
"Content-Type: text/plain; charset=ISO-8859-1\n" .
"Content-Transfer-Encoding: base64\n\n";
$headers .= chunk_split(base64_encode("$plain_text"));

//attach attachment if it's been prepared
$headers .= $attachment;


//n.b. message can then be sent like this variables:
// mail("to address", "mail_subject", "", $headers);

mail($target_email, $comments, "", $headers);

?>


It's above the public_html directory, so I can't get at it in its natural habitat in a browser.

However, if I run it from the shell, it doesn't produce an error in the log.

Hmmm... interesting Mr Bond.

Any ideas Steve? I've not got a clue why this should have anything to do with SourceGuardian.

thanks,
Drew.

Steve
15th March 2006, 20:15
Hi Drew,

I can't see what it has got to do with SourceGuardian either. What cronjob entries did you setup in cPanel?


Regards,

mr_git
15th March 2006, 20:44
Hi Steve,

the cron job which runs this script is simply this:


php backups/backup_script.php


I do have a couple of others, but they're nothing to do with PHP, and run at different times to the one in the error_log.

cheers,
Drew.

Steve
15th March 2006, 20:57
Hi Drew,

Can you try changing it to the following?

lynx -dump http://www.yourdomain.com/backups/backup_script.php

For example, if you domain was testdomain.com, and the backup script was located at /public_html/scripts/backup_script.php, then you would use:

lynx -dump http://www.testdomain.com/scripts/backup_script.php

Let me know how it goes. :)

mr_git
15th March 2006, 22:15
I'm happy to try that Steve, but it'll mean I have to move the script into the public_html directory obviously.

I can put the directory into which I move the script behind some auth, but I like the idea of not having it accessible to the web server at all.

Also, if I do put some auth on the directory, won't I need to pass the login credentials to lynx?

cheers,
Drew.

mr_git
15th March 2006, 22:36
I've tried using lynx as you suggested Steve, and it works okay (when I put the directory behind some basic auth, it told me how to give it the credentials to get past it.)

The error hasn't been reproduced in the log.

I don't mind setting it up like this, although I would prefer not to have my script(s) in a directory the web server can see, if at all possible.

At the end of the day, I can ignore the error log as the script seems to work okay despite producing the error.

However, I would quite like to know why it's happening, and to keeop the script where it is.

I appreciate you help Steve :) any idea what's behind the error though?

cheers,
Drew.

Steve
16th March 2006, 08:19
I appreciate you help Steve :) any idea what's behind the error though?
I don't really know... the only thing that I can think of is because it is being called via the command line rather than via the Apache server.

I'll have a further look into what could be causing the error. :)