Checking files on remotes help
Checking files on remotes help
- Subject: Checking files on remotes help
- From: Tod Hallberg <email@hidden>
- Date: Mon, 26 May 2008 22:16:45 -0500
- Thread-topic: Checking files on remotes help
I have a script that I have cobbled together over the years that works ok,
but I have always wanted it to be fully automated from a text file list.
Basically, the script uses appletalk to connect to 3 different computers at
remote locations. At the beginning of the script, I manually enter the
location I want to check (by location number). I would like the script to
do all the locations by itself, but the number of locations would be
determined by the number of lines in a text file.
Also, I would like some guidance on how to change it to run across IP
protocol, across the internet to static or dynamic IP's.
Thanx in advance for the help.
Any help is appreciated, especially with the repeat loops and any code
improvement. I would be interested in alternate ways of getting the file
information as well.
NOTE: Requires a folder in the Documents folder named "POSBackupCheck" for
the loge file
________________ Begin script________________
set targetServerComputer to "pos_server"
set targetServerDatadisk to ("POS_Server")
set targetServerIPaddress to (".9/")
set targetMasterComputer to "master_terminal"
set targetMasterDatadisk to ("Master_Terminal")
set targetMasterIPaddress to (".10/")
set targetRemote1Computer to "remote_1"
set targetRemote1Datadisk to ("Remote_1")
set targetRemote1IPaddress to (".11/")
set mountedServer to ""
set targetDataFolder to "POS.Archives:" as text
set TargetDataComputerUserName to "administrator"
set allTargetDataComputerUserPasswordOSX to "1890"
set allStoreInfo to ""
set DiskName to (path to startup disk) as string
set usersFolder to (path to users folder) as string
set docFolder to (path to documents folder) as string
set currUsersFolder to characters 1 thru -11 of docFolder as string
tell application "Finder"
set putAwayList to list disks
if putAwayList contains targetServerDatadisk then
eject disk targetServerDatadisk
end if
if putAwayList contains targetMasterDatadisk then
eject disk targetMasterDatadisk
end if
if putAwayList contains targetRemote1Datadisk then
eject disk targetRemote1Datadisk
end if
end tell
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Begin Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set DateNow to (current date)
set currMonth to month of (DateNow) as string
set currDate to day of (DateNow) as string
set currYear to year of (DateNow) as string
set currTime to time of (DateNow)
set dateString to currYear & "-" & currMonth & "-" & currDate
set timeString to time string of DateNow
set beginLogMessage to dateString & return & timeString & " - POSBackup
Check script beginning." & return as text
set logFile to docFolder & "POSBackupCheck:" & dateString as string
set logFile to logFile as text
set theOpenLogFile to open for access file logFile with write permission
write beginLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Begin Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set pathToInfoFile to DiskName & "Library:Application
Support:Tod_Script:StoreInfo.txt" as text
open for access file pathToInfoFile
read file pathToInfoFile as string using delimiter return
set allStoreInfo to the result
close access file pathToInfoFile
set storeNumber to ""
set storePassword to ""
set storeName to ""
set storeZoneName to ""
set targetDataComputerUserPassword to ""
display dialog "What store would you like to check? (2-42)" default answer
"" giving up after 30
set storeNumber to text returned of the result
--Get Password
set storeName to word 1 of item storeNumber of allStoreInfo as string
set storeZoneName to words 2 thru 4 of item storeNumber of allStoreInfo as
string
set targetDataComputerUserPassword to word 5 of item storeNumber of
allStoreInfo as string
(*display dialog "Store Name is :" & storeName & return & ¬
"Store Number is :" & storeNumber & return & ¬
"Store Zone is:" & storeZoneName & return & ¬
"Password is:" & targetDataComputerUserPassword & return & ¬
"OSX Password is:" & allTargetDataComputerUserPasswordOSX*)
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mount
POS_Server!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
try
set mountedServer to (mount volume "afp://" & TargetDataComputerUserName
& ":" & allTargetDataComputerUserPasswordOSX & "@172.20." & storeNumber &
targetServerIPaddress & targetServerDatadisk)
delay 5
on error
tell me to activate
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set errorLogMessage to dateString & " - " & storeNumber & " Error
mounting " & targetServerDatadisk & "." & return
set theOpenLogFile to open for access file logFile with write permission
write errorLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
display dialog "Can't find targetDataDisk. " & targetServerComputer & "
must not be sharing or is not running." giving up after 30
end try
delay 5
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mount
POS_Server!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Check
Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set pathToChosenFolder to mountedServer & targetDataFolder as string
set textOfPathToChosenFolder to pathToChosenFolder as text
set allFiles to (list folder of pathToChosenFolder without invisible)
set numberOfItems to count of allFiles
set x to 0
repeat
set x to x + 1
try
set thisItem to item x of allFiles
on error
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set errorLogMessage to dateString & " - " & storeName & " - " &
mountedServer & " No items in this computer." & return
set theOpenLogFile to open for access file logFile with write
permission
write errorLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exit repeat
end try
set pathToThisItem to textOfPathToChosenFolder & thisItem as alias
set fileInfo to info for of pathToThisItem
set fileInfoName to name of (fileInfo)
if text of thisItem contains "POSBackup" then
try
set sizeOfThisItem to size of fileInfo as integer
if sizeOfThisItem is less than 1024 then
set byteSizeOfThisItem to sizeOfThisItem as text
set byteSizeOfThisItem to byteSizeOfThisItem & " bytes" as
text
set theSize to the result
else
set kbSizeOfThisItem to sizeOfThisItem / 1024
if kbSizeOfThisItem is less than 1024 then
set kbSizeOfThisItem to kbSizeOfThisItem as text
set kbSizeOfThisItem to (characters 1 thru 4 of
kbSizeOfThisItem) & " Kb" as text
set theSize to the result
else
set mbSizeOfThisItem to kbSizeOfThisItem / 1024
if mbSizeOfThisItem is less than 1024 then
set mbSizeOfThisItem to mbSizeOfThisItem as text
set mbSizeOfThisItem to (characters 1 thru 4 of
mbSizeOfThisItem) & " Mb" as text
set theSize to the result
else
set gbSizeOfThisItem to mbSizeOfThisItem / 1024
if gbSizeOfThisItem is less than 1024 then
set gbSizeOfThisItem to gbSizeOfThisItem as text
set gbSizeOfThisItem to (characters 1 thru 4 of
gbSizeOfThisItem) & " Gb" as text
set theSize to the result
else
end if
end if
end if
end if
end try
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set LogMessage to dateString & " - " & storeName & " - " &
mountedServer & " - " & fileInfoName & " - " & theSize & return
try
set theOpenLogFile to open for access file logFile with write
permission
on error
close access theOpenLogFile
end try
write LogMessage to theOpenLogFile starting at eof
try
close access theOpenLogFile
on error
close access theOpenLogFile
end try
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end if
if x = numberOfItems then exit repeat
end repeat
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Check
Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tell application "Finder"
set putAwayList to list disks
if putAwayList contains targetServerDatadisk then
eject disk targetServerDatadisk
end if
end tell
----------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mount
Master_Terminal!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
try
set mountedServer to (mount volume "afp://" & TargetDataComputerUserName
& ":" & allTargetDataComputerUserPasswordOSX & "@172.20." & storeNumber &
targetMasterIPaddress & targetMasterDatadisk)
delay 5
on error
tell me to activate
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set errorLogMessage to dateString & " - " & storeNumber & " Error
mounting " & targetMasterDatadisk & "." & return
set theOpenLogFile to open for access file logFile with write permission
write errorLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
display dialog "Can't find targetDataDisk. " & targetMasterComputer & "
must not be sharing or is not running." giving up after 30
end try
delay 5
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mount
Master_Terminal!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Check
Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set pathToChosenFolder to mountedServer & targetDataFolder as string
set textOfPathToChosenFolder to pathToChosenFolder as text
set allFiles to (list folder of pathToChosenFolder without invisible)
set numberOfItems to count of allFiles
set x to 0
repeat
set x to x + 1
try
set thisItem to item x of allFiles
on error
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set errorLogMessage to dateString & " - " & storeName & " - " &
mountedServer & " No items in this computer." & return
set theOpenLogFile to open for access file logFile with write
permission
write errorLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exit repeat
end try
set pathToThisItem to textOfPathToChosenFolder & thisItem as alias
set fileInfo to info for of pathToThisItem
set fileInfoName to name of (fileInfo)
if text of thisItem contains "POSBackup" then
try
set sizeOfThisItem to size of fileInfo as integer
if sizeOfThisItem is less than 1024 then
set byteSizeOfThisItem to sizeOfThisItem as text
set byteSizeOfThisItem to byteSizeOfThisItem & " bytes" as
text
set theSize to the result
else
set kbSizeOfThisItem to sizeOfThisItem / 1024
if kbSizeOfThisItem is less than 1024 then
set kbSizeOfThisItem to kbSizeOfThisItem as text
set kbSizeOfThisItem to (characters 1 thru 4 of
kbSizeOfThisItem) & " Kb" as text
set theSize to the result
else
set mbSizeOfThisItem to kbSizeOfThisItem / 1024
if mbSizeOfThisItem is less than 1024 then
set mbSizeOfThisItem to mbSizeOfThisItem as text
set mbSizeOfThisItem to (characters 1 thru 4 of
mbSizeOfThisItem) & " Mb" as text
set theSize to the result
else
set gbSizeOfThisItem to mbSizeOfThisItem / 1024
if gbSizeOfThisItem is less than 1024 then
set gbSizeOfThisItem to gbSizeOfThisItem as text
set gbSizeOfThisItem to (characters 1 thru 4 of
gbSizeOfThisItem) & " Gb" as text
set theSize to the result
else
end if
end if
end if
end if
end try
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set LogMessage to dateString & " - " & storeName & " - " &
mountedServer & " - " & fileInfoName & " - " & theSize & return
try
set theOpenLogFile to open for access file logFile with write
permission
on error
close access theOpenLogFile
end try
write LogMessage to theOpenLogFile starting at eof
try
close access theOpenLogFile
on error
close access theOpenLogFile
end try
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end if
if x = numberOfItems then exit repeat
end repeat
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Check
Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tell application "Finder"
set putAwayList to list disks
if putAwayList contains targetMasterDatadisk then
eject disk targetMasterDatadisk
end if
end tell
---------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mount
Remote_1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
try
set mountedServer to (mount volume "afp://" & TargetDataComputerUserName
& ":" & allTargetDataComputerUserPasswordOSX & "@172.20." & storeNumber &
targetRemote1IPaddress & targetRemote1Datadisk)
delay 5
on error
tell me to activate
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set errorLogMessage to dateString & " - " & storeNumber & " Error
mounting " & targetRemote1Datadisk & "." & return
set theOpenLogFile to open for access file logFile with write permission
write errorLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
display dialog "Can't find targetDataDisk. " & targetRemote1Computer &
" must not be sharing or is not running." giving up after 30
end try
delay 5
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mount
Remote_1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Check
Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set pathToChosenFolder to mountedServer & targetDataFolder as string
set textOfPathToChosenFolder to pathToChosenFolder as text
set allFiles to (list folder of pathToChosenFolder without invisible)
set numberOfItems to count of allFiles
set x to 0
repeat
set x to x + 1
try
set thisItem to item x of allFiles
on error
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set errorLogMessage to dateString & " - " & storeName & " - " &
mountedServer & " No items in this computer." & return
set theOpenLogFile to open for access file logFile with write
permission
write errorLogMessage to theOpenLogFile starting at eof
close access theOpenLogFile
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Error Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exit repeat
end try
set pathToThisItem to textOfPathToChosenFolder & thisItem as alias
set fileInfo to info for of pathToThisItem
set fileInfoName to name of (fileInfo)
if text of thisItem contains "POSBackup" then
try
set sizeOfThisItem to size of fileInfo as integer
if sizeOfThisItem is less than 1024 then
set byteSizeOfThisItem to sizeOfThisItem as text
set byteSizeOfThisItem to byteSizeOfThisItem & " bytes" as
text
set theSize to the result
else
set kbSizeOfThisItem to sizeOfThisItem / 1024
if kbSizeOfThisItem is less than 1024 then
set kbSizeOfThisItem to kbSizeOfThisItem as text
set kbSizeOfThisItem to (characters 1 thru 4 of
kbSizeOfThisItem) & " Kb" as text
set theSize to the result
else
set mbSizeOfThisItem to kbSizeOfThisItem / 1024
if mbSizeOfThisItem is less than 1024 then
set mbSizeOfThisItem to mbSizeOfThisItem as text
set mbSizeOfThisItem to (characters 1 thru 4 of
mbSizeOfThisItem) & " Mb" as text
set theSize to the result
else
set gbSizeOfThisItem to mbSizeOfThisItem / 1024
if gbSizeOfThisItem is less than 1024 then
set gbSizeOfThisItem to gbSizeOfThisItem as text
set gbSizeOfThisItem to (characters 1 thru 4 of
gbSizeOfThisItem) & " Gb" as text
set theSize to the result
else
end if
end if
end if
end if
end try
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------------------------
set LogMessage to dateString & " - " & storeName & " - " &
mountedServer & " - " & fileInfoName & " - " & theSize & return
try
set theOpenLogFile to open for access file logFile with write
permission
on error
close access theOpenLogFile
end try
write LogMessage to theOpenLogFile starting at eof
try
close access theOpenLogFile
on error
close access theOpenLogFile
end try
------------------------------------------------------------------------
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Log
File!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end if
if x = numberOfItems then exit repeat
end repeat
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Check
Files!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tell application "Finder"
set putAwayList to list disks
if putAwayList contains targetRemote1Datadisk then
eject disk targetRemote1Datadisk
end if
end tell
---------------------------------
tell application "Finder"
set putAwayList to list disks
if putAwayList contains targetServerDatadisk then
eject disk targetRemote1Datadisk
end if
if putAwayList contains targetMasterDatadisk then
eject disk targetRemote1Datadisk
end if
if putAwayList contains targetRemote1Datadisk then
eject disk targetRemote1Datadisk
end if
end tell
________________ Begin script________________
Thanx
Tod
--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden