home *** CD-ROM | disk | FTP | other *** search
- // FLUPDATE.SCP - Sample Script which udates specified file(s) on Client(s).
- // Copyright (c) 2000, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 5.3 22-Aug-00 AB - Created.
- // 6.0 12-Oct-00 DB - Trim predefined variables before use.
- // - Change predefined ClientName for Lookup
- // from " " to "*".
-
- // This Script can be used to ensure that all Clients (or Clients in a Group)
- // have an up to date version of one or more specified files. The filename(s)
- // of the file(s) that need to be checked must be predefined. To pass multiple
- // filenames to the Script, use a vertical bar | to separate the names. Specific
- // Clients or Groups to be checked can also be predefined.
-
- $INCLUDE "GTCTLDIR.SCP"
- $INCLUDE "PARSE.SCP"
- $INCLUDE "RINSTR.SCP"
- $INCLUDE "TOKENS.SCP"
-
- // Predefined variables:
- // ClientName = "" Template name for Lookup (use "*" for any)
- // GroupName = "" Selects all Clients from this Group
- // Username = "SCRIPTING/GBBLLYDGKK" Username and password for Connect
- // FileNames = "NSM.LIC|CLIENT32.INI|CONTROLS.NSM" List of files to be checked
- // by the Script. The names must be separated by a vertical bar (as this cannot be used
- // in filenames).
-
- Function Main ()
- Dim ClientName as String, GroupName as String, Username as String
- Dim FileNames as String, FileNameList as List, TempList as List
- Dim Clients as List, ClientCount, FileCopyCount, FileUpdateCount
- Dim CtrlFile as String,, CLFile as String
- Dim Cmp as Integer, Atr as Integer, CtrlDir as String
- Dim x, FilePath as String
-
- SetTransport (T_TCPIP)
-
- // Initialise counter variables
-
- ClientCount = 0
- FileCopyCount = 0
- FileUpdateCount = 0
- x = 0
-
- // Trim predefined variables before use
-
- ClientName = Trim (ClientName)
- GroupName = Trim (GroupName)
- UserName = Trim (UserName)
- FileNames = Trim (FileNames)
-
- // Check the FileNames string to see if it contains a value,
- // if it does then put the filenames into a list.
-
- If FileNames = "" then
- Print "No filenames supplied!"
- else
-
- FileNameList = TokenList (FileNames, "|")
- CtrlDir = GetControlDir ()
-
- // Check that the files in the list exist. If one is not there, remove
- // it from the list. x is used to count the number of items in the list
- // so that when all the files in the original list have been searched for,
- // the Script can be sure that at least one valid file name has been
- // supplied. The Items function could be used to do this, but if there
- // were no valid filenames supplied, the list is empty and Items would
- // cause an error.
-
- For Each File in FileNameList
- FilePath = CtrlDir + "\" + File
- If FileExists (FilePath) Then
- AddItem (TempList, File)
- x = x + 1
- Else
- Print "File ", FilePath, " not found!"
- Endif
- Next
-
- If x = 0 Then
- Print "Specified files not found!"
- Else
- FileNameList = TempList
-
- // If GroupName is defined, get all the Clients in the Group
-
- If GroupName != "" Then
- Print "Selecting all Clients from Group: ", GroupName
- GetClientsInGroup (GroupName, Clients)
- Else
-
- // If ClientName is defined, see if there are any
- // Clients running which have matching names
- // Use ClientName = "*" to get all Available Clients
- // Otherwise, get all of the Known Clients
-
- If ClientName != "" Then
- If ClientName != "*" Then
- Print "Browsing for Clients matching name: ", ClientName
- Else
- ClientName = ""
- Print "Browsing for Available Clients"
- Endif
- Lookup (ClientName, Clients)
- Else
- Print "Selecting all Known Clients"
- GetAllClients (Clients)
- Endif
- Endif
-
- // Make sure that at least one Client has been found.
-
- If Items (Clients) > 0 then
-
- // Execute the following loop on all Clients found.
-
- For each CClient in Clients
- Trim (CClient)
-
- Print "----------------------------------------------------"
- Print "Trying Client ", GetClientName (CClient), "..."
-
- // Attempt to connect to the Client.
-
- If Connect (CClient, UserName) then
- ClientCount = ClientCount + 1
-
- Print "Connected to Client ", ClientCount, " ", GetClientName (CClient)
-
- // Go through the FilenameList list,
- // comparing all the files in the list.
-
- For Each CtrlFile in FilenameList
-
- // Use GetInstallDir to discover the location of the
- // required file and to create the path for the temp
- // file that the Client's file will be renamed to if it is
- // out of date.
-
- ClFile = GetInstallDir ("") + "\" + CtrlFile
- TmpFile = ParseStrPath ("*.OLD", ClFile)
- ClFile = ">" + ClFile
- CtrlFile = CtrlDir + "\" + CtrlFile
-
- // Compare the files
-
- Cmp = FileCompare (ClFile, CtrlFile)
-
- // If 1 is returned then the Client's file has the
- // wrong attributes. They will be corrected.
-
- If Cmp = 1 Then
- Print "Changing Client file's attributes."
- Atr = GetFileInfo (CtrlFile, FI_ATTRIB)
- SetAttrib (ClFile, Atr)
- Endif
-
- // If 5 is returned then the Client's file does not exist
- // (because the Control's was checked earlier).
- // The file will be copied across from the Control.
-
- If Cmp = 5 Then
- Print "Client does not have the file, copying the Control's."
- Copy (CtrlFile, ClFile)
- FileCopyCount = FileCopyCount + 1
- Endif
-
- // If the files are different, rename the Client's file
- // to a temporary .OLD file and copy the Control's file
- // to the Client. If the file is copied successfully, delete
- // the temporary file, if not then rename the .OLD file
- // back to its orriginal name.
-
- If Cmp > 1 and Cmp <5 Then
- Print "Client's file is different"
- Print "Renaming ", ClFile, " to ", TmpFile
- If FileExists (">" + TmpFile) Then
- Delete (">" + TmpFile)
- Endif
- If Rename (ClFile, TmpFile) Then
- If Copy (CtrlFile, ClFile) Then
- Print "Client's file successfully updated."
- FileUpdateCount = FileUpdateCount + 1
- Else
- Print "Could not copy the Control's file, replacing original."
- Rename (TmpFile, ClFile)
- Endif
- Else
- Print "Could not rename Client's file"
- Endif
- Endif
- Next
-
- // Disconnect and move onto the next Client
-
- Disconnect (CClient)
- Else
- Print "Could not connect to Client ", GetClientName (CCLient)
- Endif
- Next
- Else
- Print "No Clients were found!"
- Endif
-
- // Print a summary
-
- Print "Number of Clients found: ", ClientCount
- Print " Number of files copied: ", FileCopyCount
- Print " Number of files updated: ", FileUpdateCount
-
- Endif
- Endif
- End Function
-
- // This function compares two files to check for differences. If the files have the same
- // size, date, time and attributes the function returns 0. If one of these is different from
- // the other file, a number between 1 and 4 is returned, depending on the value that is
- // different. If one or both of the files don't exist, 5 is returned.
-
- Function FileCompare (FName as String, F2Name as String) as Integer
- Dim a as Integer, b as Integer
- Dim c as String, d as String
-
- FileCompare = 0
-
- If FileExists (FName) and FileExists (F2Name) Then
- a = GetFileInfo (FName, FI_SIZE)
- b = GetFileInfo (F2Name, FI_SIZE)
- If a = b Then
- a = GetFileInfo (FName, FI_DATE)
- b = GetFileInfo (F2Name, FI_DATE)
- If a = b Then
- a = GetFileInfo (FName, FI_TIME)
- b = GetFileInfo (F2Name, FI_TIME)
- If a = b Then
- c = GetFileInfo (FName, FI_ATTRIB)
- d = GetFileInfo (F2Name, FI_ATTRIB)
- If c = d Then
- Print "The files are the same."
- Else
- Print "The file attributes are different"
- FileCompare = 1
- Endif
- Else
- Print "The files have different time stamps."
- FileCompare = 2
- Endif
- Else
- Print "The files have different dates"
- FileCompare = 3
- Endif
- Else
- Print "The files are different sizes."
- FileCompare = 4
- Endif
- Else
- Print "One (or both) of the files does not exist."
- FileCompare = 5
- Endif
- End Function
-