iamdangavin

Cron

Sep 7th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * LSCU FACU DATA NIGHTLY MIGRATION BY CUSG
  5.  * SCRIPT SHOULD RUN NIGHTLY AT 2 AM EST AS CRON JOB
  6.  *
  7.  * CRON TIME OPTION:  0 2 * * *
  8.  *
  9.  * CRON COMMAND OPTIONS:
  10.  * php /path/to/script/cu_finder_cron.php
  11.  * OR
  12.  * wget -q -O /dev/null http://siteURL.org/path_to_script_from_doc_root/cu_finder_cron.php
  13.  *
  14.  * PLEASE CONTACT [email protected] WITH ISSUES - SUBJECT "LSCU CRON ISSUES"
  15.  *
  16.  */
  17.  
  18. // SET MySQL Parameters - DEFINED BY LSCU in CU-SOLUTIONS-DATA/CU-BRANCHES.PHP
  19. $dbhost = "localhost";
  20. $dbuser = "scoutbra";
  21. $dbpass = "J0S#n1Bo0";
  22. $dbname = "scoutbra_wrd1";
  23.  
  24. // EMAIL ERRORS - PLEASE LEAVE THE [email protected]/[email protected] ADDRESSES IN THERE FOR TRACKING ON OUR END.  ADD ADDITONAL ADDRESSES, SEPARATED BY COMMAS
  25. $errorsub = 'LSCU FACU DATA MIGRATION ERROR';
  26. $successsub = 'LSCU FACU DATA MIGRATION COMPLETED';
  27. $errormess = '';
  28. $errorfrom = '[email protected]';
  29.  
  30. /*
  31.  * PLEASE DO NOT EDIT ANYTHING BELOW THIS LINE!!!!
  32.  */
  33.  
  34. // VARS
  35. $buffer = '';
  36. $sqlstatements = array();
  37. $sqldata = '';
  38.  
  39. // TOKENIZED HASH TO PASS
  40. $TOKEN = 'CC56534uydR3w00-23DDf4Izzpl-09345';
  41. $hashtok = md5($TOKEN);
  42.  
  43. // CALL TO FIND A CU SCRIPT
  44.  
  45. $fields ="hashtok=".urlencode($hashtok);
  46.  
  47.         $ch=curl_init("https://natcufinder.secure.cu-village.com/client/lscu_finder/index.php");
  48.         curl_setopt($ch, CURLOPT_HEADER, 0);
  49.         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // set the fields to post
  50.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  51.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // make sure we get the response back
  52.  
  53.         $buffer = curl_exec($ch); // execute the post
  54.  
  55.         curl_close($ch); // close our session
  56.        
  57.        
  58. if(empty($buffer) || $buffer == '-1'){
  59.     // FAILED
  60.     $errormess = 'Failed to communicated correctly with CUSG API';
  61.     mail($errorto,$errorsub,$errormess,'From:'.$errorfrom);
  62. }else{
  63.     // EXECUTE SQL CALLS
  64.     $dblink = mysql_connect($dbhost,$dbuser,$dbpass);
  65.     if (!$dblink) {
  66.         $errormess = 'Failed to login correctly to MySQL service: '. mysql_error();
  67.         mail($errorto,$errorsub,$errormess,'From:'.$errorfrom);
  68.         die('Could not connect: ' . mysql_error());
  69.     }
  70.    
  71.     $db_selected = mysql_select_db($dbname,$dblink);
  72.     if (!$db_selected) {
  73.         $errormess = 'Failed to communicated correctly with local DB: '. mysql_error();
  74.         mail($errorto,$errorsub,$errormess,'From:'.$errorfrom);
  75.         die ('Can\'t use WordPress DB: ' . mysql_error());
  76.     }
  77.    
  78.     $sqlstatements = explode("\n",$buffer);
  79.     foreach($sqlstatements as $query){
  80.         $query = trim($query);
  81.         if($query != ''){
  82.             $res = mysql_query($query,$dblink);        
  83.         }
  84.     }
  85.    
  86.     $errormess = 'Nightly data migration completed';
  87.     mail($errorto,$successsub,$errormess,'From:'.$errorfrom);
  88.    
  89. }
  90.  
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment