Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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"}
  2.  
  3.  
  4. set ComputerName to computer name of (system info)
  5. set UserName to short user name of (system info)
  6. tell application "Finder" to set HDName to name of startup disk
  7.  
  8. if ComputerName = "swindon1.decentgroup.co.uk" then
  9.         --set HDName to "swindon1-internal1"
  10.         set customers to HDName & ":Volumes:swindon1-internal3:Customers (FileMaker)"
  11.         set customersForShell to "/Volumes/swindon1-internal3/Customers (FileMaker)"
  12. else
  13.         --set HDName to display dialog "Hard Drive Name: " default answer "Macintosh HD" with icon note buttons {"Cancel", "Continue"} default button "Continue"
  14.         --set HDName to text returned of HDName
  15.         set customers to HDName & ":Volumes:Customers (FileMaker)"
  16.         set customersForShell to "/Volumes/Customers (FileMaker)"
  17. end if
  18.  
  19. set FolderNamesList to CustomerListSaved
  20. set CustomerList to my listInput(FolderNamesList)
  21.  
  22. to listInput(FolderNamesList)
  23.         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
  24.         set ButtonResult to CustomerList
  25.  
  26.         if ButtonResult = false then
  27.                 AddListValue(FolderNamesList, ButtonResult)
  28.         else
  29.                 return CustomerList
  30.         end if
  31. end listInput
  32.  
  33. to AddListValue(FolderNamesList, ButtonResult)
  34.         set CustomerListButtonResult to "Add: "
  35.         set AddedListValue to display dialog CustomerListButtonResult default answer "" with icon note buttons {"Cancel", "Add"} default button "Add"
  36.         set AddedListValue to text returned of AddedListValue
  37.         copy AddedListValue to end of CustomerListSaved
  38.         listInput(FolderNamesList)
  39. end AddListValue
  40.  
  41. set CustomerNumber to 0
  42. set errorLog to "START OF LOG:
  43.  
  44. "
  45. --record how long it takes to run out of interest
  46. set TimeStart to (time string of (current date))
  47. set errorCount to 0
  48. set errorLogForTxt to ""
  49. set errorLogJustErrors to errorLog
  50. set CustomerListSize to count of CustomerList
  51. set the_files to {}
  52. set fileName to ""
  53. set CurrentDate to current date
  54. set CurrentDateDay to day of CurrentDate
  55. try
  56.         try
  57.                 repeat until CustomerNumber > (CustomerListSize - 1)
  58.                         set CustomerNumber to CustomerNumber + 1
  59.                         tell application "Finder" to set the_files to get every file of folder (customers & ":" & item CustomerNumber of CustomerList) as list
  60.                         set ListSize to count of the_files
  61.  
  62.                         --File1 Variables
  63.                         --File1 is the most recent backup
  64.                         set file1Name to name of item ListSize of the_files
  65.                         set file1Path to (((customersForShell & "/" & item CustomerNumber of CustomerList) as text) & ("/" & file1Name))
  66.                         --Modified timestamp of File1
  67.                         tell application "System Events" to set file1Modified to modification date of file file1Path
  68.                         set file1DayModified to day of file1Modified
  69.                         set file1MonthModified to month of file1Modified
  70.                         set file1TimeModified to time of file1Modified
  71.                         set file1Size to do shell script "stat -f %z " & "\"" & customersForShell & "/" & item CustomerNumber of CustomerList & "/" & file1Name & "\""
  72.  
  73.                         --File2 Variables
  74.                         --File2 is the second most recent backup
  75.                         set file2Name to name of item (ListSize - 1) of the_files
  76.                         set file2Path to (((customersForShell & "/" & item CustomerNumber of CustomerList) as text) & ("/" & file2Name))
  77.                         --Modified timestamp of File2
  78.                         tell application "System Events" to set file2Modified to modification date of file file2Path
  79.                         set file2DayModified to day of file2Modified
  80.                         set file2MonthModified to month of file2Modified
  81.                         set file2TimeModified to time of file2Modified
  82.                         set file2Size to do shell script "stat -f %z " & "\"" & customersForShell & "/" & item CustomerNumber of CustomerList & "/" & file2Name & "\""
  83.  
  84.                         set sizeError to file2Size > file1Size
  85.                         --if the backup was sent today then check if yesterdays backup was sent a day before today
  86.                         if (CurrentDateDay = file1DayModified) then
  87.                                 if sizeError then
  88.                                         set sizeDifferenceRaw to file2Size - file1Size
  89.                                         set sizeDifferenceKB to (sizeDifferenceRaw / 1000)
  90.                                         set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
  91. "
  92.                                         set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
  93. "
  94.                                         set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Size) Difference : " & sizeDifferenceKB & " KB
  95.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  96.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  97.  
  98. "
  99.                                         set errorCount to errorCount + 1
  100.  
  101.  
  102.                                 else if file2Size = file1Size then
  103.                                         set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
  104. "
  105.                                         set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
  106. "
  107.                                         set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
  108.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  109.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  110.  
  111. "
  112.                                         set errorCount to errorCount + 1
  113.  
  114.                                 else
  115.                                         set errorLog to errorLog & "All Good: " & item CustomerNumber of CustomerList & ".
  116. "
  117.                                         set errorLogForTxt to errorLogForTxt & "All Good: " & item CustomerNumber of CustomerList & "
  118.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  119.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  120.  
  121. "
  122.  
  123.                                 end if
  124.                                 --if the most recent backup was sent yesterday AND the backup before that was sent the day before then return "All Good".
  125.                         else if (CurrentDateDay - 1 = file1DayModified) and (CurrentDateDay - 2 = file2DayModified) then
  126.                                 if sizeError then
  127.                                         set sizeDifferenceRaw to file2Size - file1Size
  128.                                         set sizeDifferenceKB to (sizeDifferenceRaw / 1000)
  129.                                         set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
  130. "
  131.                                         set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Size).
  132. "
  133.                                         set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Size) Difference : " & sizeDifferenceKB & " KB
  134.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  135.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  136.  
  137. "
  138.                                         set errorCount to errorCount + 1
  139.  
  140.                                 else if file2Size ≥ file1Size then
  141.                                         set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
  142. "
  143.                                         set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
  144. "
  145.                                         set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Same Size).
  146.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  147.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  148.  
  149. "
  150.                                         set errorCount to errorCount + 1
  151.  
  152.                                 else
  153.                                         set errorLog to errorLog & "All Good: " & item CustomerNumber of CustomerList & ".
  154. "
  155.  
  156.                                         set errorLogForTxt to errorLogForTxt & "All Good: " & item CustomerNumber of CustomerList & "
  157.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  158.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  159.  
  160. "
  161.  
  162.                                 end if
  163.  
  164.                                 --if not then return a date error.
  165.                         else
  166.                                 set errorLog to errorLog & "Please Check: " & item CustomerNumber of CustomerList & " (Date).
  167. "
  168.                                 set errorLogJustErrors to errorLogJustErrors & "Please Check: " & item CustomerNumber of CustomerList & " (Date).
  169. "
  170.                                 set errorLogForTxt to errorLogForTxt & "Please Check: " & item CustomerNumber of CustomerList & " (Date).
  171.                File : " & file1Name & " |  Size : " & file1Size & " |  Date : " & file1Modified & "
  172.                File : " & file2Name & " |  Size : " & file2Size & " |  Date : " & file2Modified & "
  173.  
  174. "
  175.  
  176.                                 set errorCount to errorCount + 1
  177.  
  178.                         end if
  179.                 end repeat
  180.         on error
  181.                 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?"
  182.         end try
  183.         set errorLog to errorLog & "
  184. END OF LOG."
  185.         set errorLogJustErrors to errorLogJustErrors & "
  186. END OF LOG."
  187.         try
  188.                 set TimeEnd to (time string of (current date))
  189.                 --Write
  190.                 set logFile to open for access (choose file name) with write permission
  191.                 write "Script started at: " & TimeStart & "
  192. " to logFile
  193.                 write "Script ended at:   " & TimeEnd & "
  194. " to logFile
  195.                 write "Ran by: " & UserName & "
  196. " to logFile
  197.                 write "There were " & errorCount & " total errors
  198. " to logFile
  199.                 write errorLogForTxt to logFile
  200.                 close access logFile
  201.         on error
  202.                 display dialog "A file with that name in that directory is already open."
  203.         end try
  204.  
  205.         set ResultDisplay to display dialog errorLog with icon note buttons {"Errors", "OK"} default button "OK"
  206.         set ResultDisplay to button returned of ResultDisplay
  207.         if ResultDisplay = "Errors" then
  208.                 try
  209.                         display dialog errorLogJustErrors with icon note buttons {"OK"} default button "OK"
  210.                 on error
  211.                         --do nothing
  212.                 end try
  213.         end if
  214.         set success to 1
  215. on error
  216.         --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"
  217.         tell application "Finder"
  218.                 activate
  219.                 mount volume "smb://172.16.16.16/Customers (FileMaker)"
  220.         end tell
  221. end try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement