![]() |
|
|||||||
| OthelloHosts.net - Shared Hosting (Personal + Business) Help, Advice and Discussion on Shared (Virtual) Hosting Services for Home and Business users. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Junior Member
Join Date: Mar 2006
Posts: 6
|
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: Quote:
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 |
|
|
|
|
|
|
#2 |
|
StaticHost CEO
![]() |
Hello,
That's strange - does your script that is ran on the cronjob use SourceGuardian at all? Regards,
__________________
[B]Steve McManus[/B] Founder and CEO of StaticHost Internet Services |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Mar 2006
Posts: 6
|
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. |
|
|
|
|
|
#4 | |
|
StaticHost CEO
![]() |
Hi Drew,
Quote:
Does it create entries in your error_log if it's called normally via a web browser?Regards,
__________________
[B]Steve McManus[/B] Founder and CEO of StaticHost Internet Services |
|
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Mar 2006
Posts: 6
|
Here's the script:
Code:
<?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);
?>
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. |
|
|
|
|
|
#6 |
|
StaticHost CEO
![]() |
Hi Drew,
I can't see what it has got to do with SourceGuardian either. What cronjob entries did you setup in cPanel? Regards,
__________________
[B]Steve McManus[/B] Founder and CEO of StaticHost Internet Services |
|
|
|
|
|
#7 | |
|
Junior Member
Join Date: Mar 2006
Posts: 6
|
Hi Steve,
the cron job which runs this script is simply this: Quote:
cheers, Drew. |
|
|
|
|
|
|
#8 | ||
|
StaticHost CEO
![]() |
Hi Drew,
Can you try changing it to the following? Quote:
Quote:
__________________
[B]Steve McManus[/B] Founder and CEO of StaticHost Internet Services |
||
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Mar 2006
Posts: 6
|
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. |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Mar 2006
Posts: 6
|
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|