Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- property CustomerListSaved : {"AIT", "ApexBuildingProducts", "BNP", "CAR", "Datanet", "DKA", "DQM", "EBT", "Golf Car UK Ltd", "Hilo", "KielyBrothers", "LGH", "MediaClash", "Nathan", "OrchardEnergy", "Plunkett", "ProductionFactory", "QF", "Rospa", "SBC", "Timberpride", "Zone"}
- set ComputerName to computer name of (system info)
- set UserName to short user name of (system info)
- tell application "Finder" to set HDName to name of startup disk
- if ComputerName = "swindon1.decentgroup.co.uk" then
- --set HDName to "swindon1-internal1"
- set customers to HDName & ":Volumes:swindon1-internal3:Customers (FileMaker)"
- set customersForShell to "/Volumes/swindon1-internal3/Customers (FileMaker)"
- else
- --set HDName to display dialog "Hard Drive Name: " default answer "Macintosh HD" with icon note buttons {"Cancel", "Continue"} default button "Continue"
- --set HDName to text returned of HDName
- set customers to HDName & ":Volumes:Customers (FileMaker)"
- set customersForShell to "/Volumes/Customers (FileMaker)"
- end if
- set FolderNamesList to CustomerListSaved
- set CustomerList to my listInput(FolderNamesList)
- to listInput(FolderNamesList)
- set CustomerList to choose from list FolderNamesList with prompt "Select folders you wish to check" OK button name {"Continue"} cancel button name {"Add"} with multiple selections allowed
- set ButtonResult to CustomerList
- if ButtonResult = false then
- AddListValue(FolderNamesList, ButtonResult)
- else
- return CustomerList
- end if
- end listInput
- to AddListValue(FolderNamesList, ButtonResult)
- set CustomerListButtonResult to "Add: "
- set AddedListValue to display dialog CustomerListButtonResult default answer "" with icon note buttons {"Cancel", "Add"} default button "Add"
- set AddedListValue to text returned of AddedListValue
- copy AddedListValue to end of CustomerListSaved
- listInput(FolderNamesList)
- end AddListValue
- set CustomerNumber to 0
- set errorLog to "START OF LOG:
- "
- --record how long it takes to run out of interest
- set TimeStart to (time string of (current date))
- set errorCount to 0
- set errorLogForTxt to ""
- set errorLogJustErrors to errorLog
- set CustomerListSize to count of CustomerList
- set the_files to {}
- set fileName to ""
- set CurrentDate to current date
- set CurrentDateDay to day of CurrentDate
- try
- try
- repeat until CustomerNumber > (CustomerListSize - 1)
- set CustomerNumber to CustomerNumber + 1
- tell application "Finder" to set the_files to get every file of folder (customers & ":" & item CustomerNumber of CustomerList) as list
- set ListSize to count of the_files
- --File1 Variables
- --File1 is the most recent backup
- set file1Name to name of item ListSize of the_files
- set file1Path to (((customersForShell & "/" & item CustomerNumber of CustomerList) as text) & ("/" & file1Name))
- --Modified timestamp of File1
- tell application "System Events" to set file1Modified to modification date of file file1Path
- set file1DayModified to day of file1Modified
- set file1MonthModified to month of file1Modified
- set file1TimeModified to time of file1Modified
- set file1Size to do shell script "stat -f %z " & "\"" & customersForShell & "/" & item CustomerNumber of CustomerList & "/" & file1Name & "\""
- --File2 Variables
- --File2 is the second most recent backup
- set file2Name to name of item (ListSize - 1) of the_files
- set file2Path to (((customersForShell & "/" & item CustomerNumber of CustomerList) as text) & ("/" & file2Name))
- --Modified timestamp of File2
- tell application "System Events" to set file2Modified to modification date of file file2Path
- set file2DayModified to day of file2Modified
- set file2MonthModified to month of file2Modified
- set file2TimeModified to time of file2Modified
- set file2Size to do shell script "stat -f %z " & "\"" & customersForShell & "/" & item CustomerNumber of CustomerList & "/" & file2Name & "\""
- set sizeError to file2Size > file1Size
- --if the backup was sent today then check if yesterdays backup was sent a day before today
- if (CurrentDateDay = file1DayModified) then
- if sizeError then
- set sizeDifferenceRaw to file2Size - file1Size
- set sizeDifferenceKB to (sizeDifferenceRaw / 1000)
- set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
- "
- set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
- "
- set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Size) Difference : " & sizeDifferenceKB & " KB
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- set errorCount to errorCount + 1
- else if file2Size = file1Size then
- set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
- "
- set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
- "
- set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- set errorCount to errorCount + 1
- else
- set errorLog to errorLog & "All Good: " & item CustomerNumber of CustomerList & ".
- "
- set errorLogForTxt to errorLogForTxt & "All Good: " & item CustomerNumber of CustomerList & "
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- end if
- --if the most recent backup was sent yesterday AND the backup before that was sent the day before then return "All Good".
- else if (CurrentDateDay - 1 = file1DayModified) and (CurrentDateDay - 2 = file2DayModified) then
- if sizeError then
- set sizeDifferenceRaw to file2Size - file1Size
- set sizeDifferenceKB to (sizeDifferenceRaw / 1000)
- set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
- "
- set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
- "
- set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Size) Difference : " & sizeDifferenceKB & " KB
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- set errorCount to errorCount + 1
- else if file2Size ≥ file1Size then
- set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
- "
- set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
- "
- set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- set errorCount to errorCount + 1
- else
- set errorLog to errorLog & "All Good: " & item CustomerNumber of CustomerList & ".
- "
- set errorLogForTxt to errorLogForTxt & "All Good: " & item CustomerNumber of CustomerList & "
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- end if
- --if not then return a date error.
- else
- set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Date).
- "
- set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Date).
- "
- set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Date).
- File : " & file1Name & " | Size : " & file1Size & " | Date : " & file1Modified & "
- File : " & file2Name & " | Size : " & file2Size & " | Date : " & file2Modified & "
- "
- set errorCount to errorCount + 1
- end if
- end repeat
- on error
- display dialog "There was an issue when checking the backup files. Have you accidentally selected a client from the list that no longer exists or added a new one with an incorrect name?"
- end try
- set errorLog to errorLog & "
- END OF LOG."
- set errorLogJustErrors to errorLogJustErrors & "
- END OF LOG."
- try
- set TimeEnd to (time string of (current date))
- --Write
- set logFile to open for access (choose file name) with write permission
- write "Script started at: " & TimeStart & "
- " to logFile
- write "Script ended at: " & TimeEnd & "
- " to logFile
- write "Ran by: " & UserName & "
- " to logFile
- write "There were " & errorCount & " total errors
- " to logFile
- write errorLogForTxt to logFile
- close access logFile
- on error
- display dialog "A file with that name in that directory is already open."
- end try
- set ResultDisplay to display dialog errorLog with icon note buttons {"Errors", "OK"} default button "OK"
- set ResultDisplay to button returned of ResultDisplay
- if ResultDisplay = "Errors" then
- try
- display dialog errorLogJustErrors with icon note buttons {"OK"} default button "OK"
- on error
- --do nothing
- end try
- end if
- set success to 1
- on error
- --display dialog "Please ensure that you have the \"Customers (FileMaker)\" drive mounted and that the folder you are trying to check exists within it. " with icon note buttons {"OK"} default button "OK"
- tell application "Finder"
- activate
- mount volume "smb://172.16.16.16/Customers (FileMaker)"
- end tell
- end try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement