aeroswat Posted June 24, 2010 Share Posted June 24, 2010 I'm using bluehost as a hosting site and I can't seem to get my crons to execute that i've set up. I've tried both of these and neither work > */5 * * * * /usr/bin/php -q /home2/aircborg/crons/cron-backup.php */5 * * * * php -f /home2/username/crons/cron-backup.php Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/ Share on other sites More sharing options...
premiso Posted June 24, 2010 Share Posted June 24, 2010 Have you tried running the script on your own (given that you have ssh access) to make sure that it runs and parses just fine. You could have an error in the script and that is why. You can "redirect" the output from that into a log file to test this as well: */5 * * * * /usr/bin/php -q /home2/aircborg/crons/cron-backup.php > /tmp/cron_log.log Which should redirect the output to that log file where you can view it to see if there was an error etc. Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076690 Share on other sites More sharing options...
aeroswat Posted June 24, 2010 Author Share Posted June 24, 2010 Have you tried running the script on your own (given that you have ssh access) to make sure that it runs and parses just fine. You could have an error in the script and that is why. You can "redirect" the output from that into a log file to test this as well: */5 * * * * /usr/bin/php -q /home2/aircborg/crons/cron-backup.php > /tmp/cron_log.log Which should redirect the output to that log file where you can view it to see if there was an error etc. thx. I'll try it out but I have tested the file before and it was working. I'll try to log out. Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076691 Share on other sites More sharing options...
aeroswat Posted June 24, 2010 Author Share Posted June 24, 2010 The log file has nothing in it... >< It echo's when I run it but it doesn't do anything when it runs the cron Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076704 Share on other sites More sharing options...
aeroswat Posted June 24, 2010 Author Share Posted June 24, 2010 bring it to the top. Can anyone brainstorm with me? Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076791 Share on other sites More sharing options...
aeroswat Posted June 24, 2010 Author Share Posted June 24, 2010 Here i'll post the code of the file too. Maybe someone can see something that might be causing a problem require_once('src/config.php'); $filePath='../backups/'; $dir = opendir($filePath) or die(mysql_error()); $filelist = array(); $filelist[0] = 99999999999999; while ($file = readdir($dir)) { if(eregi("\AUTOMATIC",$file)) { if(mktime((substr($file,33,2)=='AM' ? substr($file,28,2) : (substr($file,28,2)+12)),substr($file,31,2),0,substr($file,17,2),substr($file,20,2),substr($file,23,4)) < $filelist[0]) { $filelist[0] = mktime((substr($file,33,2)=='AM' ? substr($file,28,2) : (substr($file,28,2)+12)),substr($file,31,2),0,substr($file,17,2),substr($file,20,2),substr($file,23,4)); $filelist[1] = $file; } } } $delfile = $filePath . $filelist[1]; unlink($delfile); $mysqldump_version="1.02"; $output_messages=array(); $mysql_host=DB_HOST; $mysql_database=DBA_DATABASE; $mysql_username=DBA_USER; $mysql_password=DB_PASSWORD; $filename = "../backups/AUTOMATIC_orders_" . date('m_d_Y_h-iA') . ".sql"; function _mysqldump($mysql_database) { global $filename; $sql="show tables;"; $result= mysql_query($sql) or die(mysql_error()); if( $result) { while( $row= mysql_fetch_row($result)) { _mysqldump_table_structure($row[0]); _mysqldump_table_data($row[0]); } } else { //echo "/* no tables in $mysql_database */\n"; $content = "/* no tables in $mysql_database */\n"; $handle = fopen($filename, 'a+'); fwrite($handle, $content); fclose($handle); } mysql_free_result($result); } function _mysqldump_table_structure($table) { global $filename; $handle = fopen($filename, 'a+'); $content = "/* Table structure for table `$table` */\n"; fwrite($handle, $content); $content = "DROP TABLE IF EXISTS `$table`;\n\n"; fwrite($handle, $content); $sql="show create table `$table`; "; $result=mysql_query($sql); if( $result) { if($row= mysql_fetch_assoc($result)) { $content = $row['Create Table'].";\n\n"; fwrite($handle, $content); } } mysql_free_result($result); } function _mysqldump_table_data($table) { global $filename; $handle = fopen($filename, 'a+'); $sql="select * from `$table`;"; $result=mysql_query($sql); if( $result) { $num_rows= mysql_num_rows($result); $num_fields= mysql_num_fields($result); if( $num_rows > 0) { $content = "/* dumping data for table `$table` */\n"; fwrite($handle, $content); $field_type=array(); $i=0; while( $i < $num_fields) { $meta= mysql_fetch_field($result, $i); array_push($field_type, $meta->type); $i++; } //print_r( $field_type); //echo "insert into `$table` values\n"; $index=0; while( $row= mysql_fetch_row($result)) { if($index % 100 == 0) {$content = "insert into `$table` values\n"; fwrite($handle, $content);} $content = "("; for( $i=0; $i < $num_fields; $i++) { if( is_null( $row[$i])) $content .= "null"; else { switch( $field_type[$i]) { case 'int': $content .= $row[$i]; break; case 'string': case 'blob' : default: $stre = str_replace(";",":",mysql_real_escape_string($row[$i])); //echo "'".mysql_real_escape_string($row[$i])."'"; $content .= "'".$stre."'"; } } if( $i < $num_fields-1) $content .= ","; } $content .= ")"; fwrite($handle, $content); if( $index < $num_rows-1 && (($index+1) % 100 != 0)) $content = ","; else $content = ";"; $content .= "\n"; fwrite($handle, $content); $index++; } } } mysql_free_result($result); $content = "\n"; fwrite($handle, $content); fclose($handle); } function _mysql_test($mysql_host,$mysql_database, $mysql_username, $mysql_password) { global $output_messages; $link = mysql_connect($mysql_host, $mysql_username, $mysql_password); if (!$link) { array_push($output_messages, 'Could not connect: ' . mysql_error()); } else { array_push ($output_messages,"Connected with MySQL server:$mysql_username@$mysql_host successfully"); $db_selected = mysql_select_db($mysql_database, $link); if (!$db_selected) { array_push ($output_messages,'Can\'t use $mysql_database : ' . mysql_error()); } else array_push ($output_messages,"Connected with MySQL database:$mysql_database successfully"); } } _mysql_test($mysql_host,$mysql_database, $mysql_username, $mysql_password); $content = "/*mysqldump.php version $mysqldump_version */\n"; $handle = fopen($filename, 'x+'); fwrite($handle, $content); fclose($handle); _mysqldump($mysql_database) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076797 Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 When you run a script in a cronjob, your current working directory is not the same as it is when you log in. Use full paths when referencing files. Ken Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076799 Share on other sites More sharing options...
aeroswat Posted June 24, 2010 Author Share Posted June 24, 2010 When you run a script in a cronjob, your current working directory is not the same as it is when you log in. Use full paths when referencing files. Ken That makes sense! Thank you! I'm going to try that out and see if it works for me. Quote Link to comment https://forums.phpfreaks.com/topic/205750-irritated-with-cron-jobs/#findComment-1076803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.