Thread: Cronjob madness

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Location
    California
    Posts
    158
    Rep Power
    16

    Cronjob madness


    I get an email for each time a cron job is ran? Is there anyway to stop that?
  2. #2
  3. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    21
    Alex
    (http://www.alex-greg.com)
  4. #3
  5. IT Dept Scapegoat
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    169
    Rep Power
    16
    Thx Alexgreg. I use php on the cli to backup mysql databases, and even though I have > /dev/null I get duplicate function errors. It still runs, so I had been ignoring it, but now I won't get the stderr emailed to me.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,960
    Rep Power
    194
    I get duplicate function errors
    The right way would be correcting your code instead of supressing the error messages...
    If you donīt want to do that, the workarounds are:

    The php way: "error_reporting(E_NONE)";
    The shell way: "2>/dev/null" after your ">/dev/null"
    Or disable *all* cron messages: add "MAILTO=" at the beginning of the contab
  8. #5
  9. IT Dept Scapegoat
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    169
    Rep Power
    16
    Well, you're right, fixing things is the way to go, I just haven't had time, especially when everything is working, and the error messages seem extraneous. I think it's related to the fact that I'm calling /usr/bin/php, and it's already running via apache...
  10. #6
  11. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    21
    I think it's related to the fact that I'm calling /usr/bin/php, and it's already running via apache...
    Wrong assumption. Calling /usr/bin/php starts up a new PHP process with no relation to the PHP running inside Apache. The error is due to the fact that you are defining a function twice.
    Alex
    (http://www.alex-greg.com)
  12. #7
  13. IT Dept Scapegoat
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    169
    Rep Power
    16
    Well, that's what I originally thought, too. My script was something I downloaded from phpfreaks and changed a bit.

    BUT... when I went into the script to track it down, I realized there are NO functions in it. hmmmm... well the top line of the script reads:
    Code:
    #!/usr/bin/php -q
    I decided to try just invoking php from the cli using the same command, and I get the error messages, all pertaining to mysql. I'm pretty sure it's every mysql function, too.

    In any event, it's puzzling and bothersome, but it hasn't elevated itself above gotta-do things (yet). Right now, it's only something I'd LIKE to fix.

    Still, if you have any ideas, I would be grateful!
  14. #8
  15. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    21
    Still, if you have any ideas, I would be grateful!
    You'll need to provide the script, and the exact error message(s) you get.
    Alex
    (http://www.alex-greg.com)
  16. #9
  17. IT Dept Scapegoat
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    169
    Rep Power
    16
    I can do that.
    Code:
    #!/usr/bin/php -q
    <?php
    
    // configure your database variables below:
    $dbhost = 'localhost'; // Server address of your MySQL Server
    $dbuser = 'root'; // Username to access MySQL database
    $dbpass = 'mypass'; // Password to access MySQL database
    $dbname = 'mydb'; // Database Name
    
    // Optional Options You May Optionally Configure
    
    $use_gzip = "yes";  // Set to No if you don't want the files sent in .gz format
    $remove_sql_file = "yes"; // Set this to yes if you want to remove the .sql file after gzipping. Yes is recommended.
    $remove_gzip_file = "no"; // Set this to yes if you want to delete the gzip file also. I recommend leaving it to "no"
     
    // Configure the path that this script resides on your server.
    
    $savepath = "/mnt/hawk"; // Full path to this directory. Do not use trailing slash!
    
    $send_email_w_file = "no";  // Do you want this database backup sent to your email? Fill out the next 2 lines
    $to = "furmanc@empirekosher.com";  // Who to send the emails to
    $from = "backup@empirekosher.com"; // Who should the emails be sent from?
    $senddate = date("j F Y");
    $subject = "MySQL Database Backup - $senddate"; // Subject in the email to be sent.
    $headers = "From: $from";
    if ($send_email_w_file == "yes") {
    	$message = "Your db has been backed up and attached.";
    } else {
    	$message = "Your db has been backed up and placed in $savepath.";
    }
    
    $use_ftp = "no"; // Do you want this database backup uploaded to an ftp server? Fill out the next 4 lines
    $ftp_server = "localhost"; // FTP hostname
    $ftp_user_name = "ftp_username"; // FTP username
    $ftp_user_pass = "ftp_password"; // FTP password
    $ftp_path = "/"; // This is the path to upload on your ftp server!
    
    // Do not Modify below this line! It will void your warranty!
    
    	$date = date("mdy-hia");
    	$filename = "$savepath/$dbname-$date.sql";	
    	passthru("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname >$filename");
    	
    	if($use_gzip=="yes"){
    		$zipline = "tar -czf ".$dbname."-".$date."_sql.tar.gz $dbname-$date.sql";
    		shell_exec($zipline);
    	}
    	if($remove_sql_file=="yes"){
    		exec("rm -r -f $filename");
    	}
    	
    	if($use_gzip=="yes"){
    		$filename2 = "$savepath/".$dbname."-".$date."_sql.tar.gz";
    	} else {
    		$filename2 = "$savepath/$dbname-$date.sql";
    	}
    	
    	
    	if($send_email_w_file == "yes" ){
    		$fileatt_type = filetype($filename2);
    		$fileatt_name = "".$dbname."-".$date."_sql.tar.gz";
    		
    		
    		// Read the file to be attached ('rb' = read binary)
    		$file = fopen($filename2,'rb');
    		$data = fread($file,filesize($filename2));
    		fclose($file);
    	
    		// Generate a boundary string
    		$semi_rand = md5(time());
    		$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    	
    		// Add the headers for a file attachment
    		$headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\"";
    	
    		// Add a multipart boundary above the plain message
    		$message = "This is a multi-part message in MIME format.\n\n" ."--{$mime_boundary}\n" ."Content-Type: text/plain; charset=\"iso-8859-1\"\n" ."Content-Transfer-Encoding: 7bit\n\n" .
    		$message . "\n\n";
    	
    		// Base64 encode the file data
    		$data = chunk_split(base64_encode($data));
    	
    		// Add file attachment to the message
    		$message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name=\"{$fileatt_name}\"\n" ."Content-Disposition: attachment;\n" ." filename=\"{$fileatt_name}\"\n" ."Content-Transfer-Encoding: base64\n\n" .
    		$data . "\n\n" ."--{$mime_boundary}--\n";
    	}
    	// Send the message
    	$ok = @mail($to, $subject, $message, $headers);
    	if ($ok) {
    		echo "<h4><center>Database backup created and sent! File name $filename2</center></h4>";
    	} else {
    		echo "<h4><center>Mail could not be sent. Sorry!</center></h4>";
    	}
    	
    	if($use_ftp == "yes"){
    		$ftpconnect = "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2";
    		shell_exec($ftpconnect);
    		echo "<h4><center>$filename2 Was created and uploaded to your FTP server!</center></h4>";
    	
    	}
    	
    	if($remove_gzip_file=="yes"){
    		exec("rm -r -f $filename2");
    	}
    
    ?>
    Error messages:
    Code:
    PHP Warning:  Function registration failed - duplicate name - mysql_connect in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_pconnect in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_close in Unknown
    on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_select_db in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_create_db in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_drop_db in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_query in Unknown
    on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_unbuffered_query
    in Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_db_query in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_list_dbs in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_list_tables in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_list_fields in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_error in Unknown
    on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_errno in Unknown
    on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_affected_rows in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_insert_id in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_result in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_num_rows in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_num_fields in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fetch_row in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fetch_array in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fetch_assoc in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fetch_object in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_data_seek in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fetch_lengths in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fetch_field in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_field_seek in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_free_result in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_field_name in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_field_table in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_field_len in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_field_type in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_field_flags in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_escape_string in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_get_client_info
    in Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_get_host_info in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_get_proto_info
    in Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_get_server_info
    in Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql in Unknown on
    line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fieldname in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fieldtable in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fieldlen in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fieldtype in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_fieldflags in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_selectdb in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_createdb in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_dropdb in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_freeresult in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_numfields in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_numrows in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_listdbs in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_listtables in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_listfields in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_db_name in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_dbname in
    Unknown on line 0
    PHP Warning:  Function registration failed - duplicate name - mysql_tablename in
    Unknown on line 0
    PHP Warning:  mysql:  Unable to register functions, unable to load in Unknown on line 0
    Thanks,
    CF
  18. #10
  19. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    21
    I had this problem a while ago - it was related to my php.ini. Do similar errors appear in your Apache ErrorLog when you restart it?

    Post your php.ini file (as an attachment, please!).
    Alex
    (http://www.alex-greg.com)
  20. #11
  21. IT Dept Scapegoat
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    169
    Rep Power
    16
    Alex,

    Thx, man. Yes, as a matter of fact, I do get these errors when I restart apache.

    Here is my php.ini.
    Attached Files
    Thanks,
    CF

IMN logo majestic logo threadwatch logo seochat tools logo