#!/usr/local/bin/expect -f # ## PROPERTY OF BRANT PUTTKAMMER, PLEASE CONTACT ME IF YOU HAVE QUESTIONS ## PLEASE USE CAUTION WHEN RUNNING THIS PROGRAM ON YOUR SYSTEM # DATEADD FUNCTIONS AND VARIABLES INCLUDED BELOW source /udadmin/expectscripts/DateFormats.exp source /udadmin/expectscripts/ExpectConfig.exp set ScriptName "every-day-00.exp" # TURN ON LOGGING - SET LOG VARIABLE NAME set LogFileName "/udadmin/expectlogs/EVERY-DAY-00-$FileDate.log" log_file $LogFileName # CHANGE FILE PERMISSIONS AND OWNER ON LOG FILE system "chmod 777 $LogFileName" system "chown expect $LogFileName" # APPEND ME DATES TO VARIABLE BELOW IN CASE YOU WANT TO RUN A TAPE BACKUP ON SPECIFIED DAY # MAKE SURE TO INCLUDE A SPACE BETWEEN EACH DATE - " MMDDYY MMDDYY" append MonthEndDates " 122012 121913 122214 122815" set UpgradeDelayTimeSeconds 14400 set UpgradeDelayTimeMinutes [expr $UpgradeDelayTimeSeconds/60] set DisplayMonthEndDate [timestamp -format "%B %d, %Y" -seconds $time] set HolidayCommand "echo 'Subject:EVERY-DAY-00 Notification\nThe script EVERY DAY 00 will also run a tape backup because today, $DisplayMonthEndDate, is a set as a backup night. Tape backup will begin in 45 minutes - tape backups will only run if it is scheduled (tape backups no longer run, January 2015).\n\nThe script manual_merge.exp will run after an additional sleep time has passed. This gives all necessary backups time to complete on month end.' | sendmail DistroEmailGroup" # GO THROUGH EACH HOLIDAY DATE TO TEST IF TODAY IS A HOLIDAY for {set counter [expr [llength $HolidayDates]-1]} {$counter>=0} {incr counter -1} { # GET THE CURRENT HOLIDAY FROM LIST set HolidaySelected [lindex $HolidayDates $counter] if {$HolidaySelected == $CurrentDate} { set TextString "TRUE" set DisplayHolidayDate [timestamp -format "%B %d, %Y" -seconds $time] set HolidayCommand "echo 'Subject:EVERY-DAY-00 was Skipped\nThe script EVERY DAY 00 was skipped because today, $DisplayHolidayDate, is a holiday.\n\nThe following scripts were skipped: FINISH.exp, mirro_split.exp, CU475.exp, FIX-ATR29.exp, gl_branch_delete.exp, script1.exp, script2.exp, script3.exp, manual_merge.exp.' | sendmail DistroEmailGroup" } else { } } # GO THROUGH EACH MONTH END DATE TO TEST IF TODAY IS MONTH END for {set counter [expr [llength $MonthEndDates]-1]} {$counter>=0} {incr counter -1} { # GET THE CURRENT MONTH END FROM LIST set MonthEndSelected [lindex $MonthEndDates $counter] if {$MonthEndSelected == $CurrentDate} { set TextString2 "TRUE" set DisplayMonthEndDate [timestamp -format "%B %d, %Y" -seconds $time] set HolidayCommand "echo 'Subject:EVERY-DAY-00 Notification\nThe script EVERY DAY 00 will sleep an extra $UpgradeDelayTimeMinutes minutes ($UpgradeDelayTimeSeconds seconds) because today, $DisplayMonthEndDate, is a set as an upgrade/processing/special night. After the additional sleep period, the script will resume normal delays before the mirrors are merged.' | sendmail DistroEmailGroup" } else { } } if {$TextString == "TRUE"} { # SYSTEM IS CLOSED - SPLIT FOR BACKUP system $HolidayCommand system "/udadmin/expectscripts/mirror_split.exp" # SLEEP FOR 4 HOURS BEFORE RUNNING MERGE sleep 14400 system "/udadmin/expectscripts/manual_merge.exp" } else { system "/udadmin/expectscripts/FINISH.exp" system "/udadmin/expectscripts/mirror_split.exp" system "/udadmin/expectscripts/CU475.exp" system "/udadmin/expectscripts/FIX-ATR29.exp" system "/udadmin/expectscripts/gl_branch_delete.exp" system "/udadmin/expectscripts/script1.exp" system "/udadmin/expectscripts/script2.exp" system "/udadmin/expectscripts/script3.exp" if {($CurrentDate == $LastDayOfMonthNumeric)} { system $HolidayCommand # SLEEP FOR 8 HOURS BEFORE RUNNING MERGE if {$CurrentMonth != 12} { sleep 28800 } else { } # YEAR END SLEEP CHANGE - 4:00 HOURS if {$CurrentMonth == 12} { sleep 14400 } else { } } elseif {($TextString2 == "TRUE")} { # SLEEP FOR 45 MINUTES BEFORE BEGINNING TAPE BACKUP - ALLOWS FOR EOM SCRIPT TO RUN QUICKER # TAPE BACKUP WILL BEGIN AROUND 10:45 PM, TYPICALLY TAKES ABOUT 75 MINUTES TO RUN BACKUP system $HolidayCommand # SLEEP FOR 3.5 HOURS BEFORE SLEEPING AGAIN - THIS ALLOWS FOR UPGRADE OR SYSTEM CHANGES sleep $UpgradeDelayTimeSeconds # SLEEP FOR 6 HOURS BEFORE RUNNING MERGE sleep 21600 } else { # IT IS NOT PERIOD END - DETERMINE SLEEP TIME BEFORE MERGE # SLEEP FOR 6 HOURS BEFORE RUNNING MERGE sleep 21600 } # TYPICALLY AROUND 4:00 AM system "/udadmin/expectscripts/manual_merge.exp" }