home *** CD-ROM | disk | FTP | other *** search
- // GRPFLUPD.SCP - Sample Script which udates specified file(s) on the
- // Client(s) in a Group.
- // Copyright (c) 2001, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 6.10 30-Apr-01 DB - Created, using FLUPDATE v6.00. 12-Oct-00.
- // 01-May-01 DB - Add Group and Network processing code.
- // 02-May-01 DB - Add file comparison code and test dialup.
- // 03-May-01 DB - Fix remote/local dial/hangup code.
- // 04-May-01 DB - Add error tracking and retry restart code.
- // 7.0 20-Mar-02 DB - Separate built-in $INCLUDEs to separate files.
-
- // This Script is be used to ensure that all Clients (or all 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 "ADDTOLOG.SCP"
- $INCLUDE "FCOMPARE.SCP"
- // $INCLUDE "GTCTLDIR.SCP"
- $INCLUDE "GTCTLFL.SCP"
- $INCLUDE "GTGROUP.SCP"
- $INCLUDE "GTREMOTE.SCP"
- $INCLUDE "PARSE.SCP"
- $INCLUDE "RINSTR.SCP"
- $INCLUDE "TOKENS.SCP"
-
- // Predefined variables:
- // GroupName = "" Updates all Clients in this Group
- // Password = "GBBLLYDGKK" Encrypted password for remote network
- // RootPath = <Control Directory>\<Group Name> Root directory for Group updates
- // Username = "SCRIPTING/GBBLLYDGKK" Username and password for Connect
- //
- // The following are not currently implemented:
- // ClientName = "" Template name for Lookup (use "*" for any)
-
- Function Main ()
- Dim ClientName as String, GroupName as String
- Dim Username as String, Password as String
- Dim FileNames as String, FileNameList as List
- Dim RootPath as String, OutputPath as String, LogFilePath as String
- Dim GroupList as List, ClientCount, Member as String, SplitLine as List
- Dim Name as String, Address as String, Transport as Integer
- Dim Location as Integer, Network as String, NetworkInfo as List
- Dim DialNumber as String, LastDialled as String
- Dim NextTransport as Integer, LastTransport as Integer
- Dim FileCopyCount, FileUpdateCount, FileComparison
- Dim ConnectErrors, DialErrors, FileErrors, TotalErrors
- Dim ErrorsForThisClient, RetryList as List
- Dim Handle, Line as String, Lines
- Dim CtrlFile as String, CLFile as String,TempList as List
- Dim Cmp as Integer, Atr as Integer, ClientInfo as List, CtrlDir as String
- Dim x, FilePath as String
-
- // Initialise counter variables
-
- ClientCount = 0
- FileCopyCount = 0
- FileUpdateCount = 0
- Lines = 0
- ConnectErrors = 0
- DialErrors = 0
- FileErrors = 0
- TotalErrors = 0
-
- // Trim predefined variables before use
-
- ClientName = Trim (ClientName)
- GroupName = Trim (GroupName)
- UserName = Trim (UserName)
- RootPath = Trim (RootPath)
- FileNames = Trim (FileNames)
-
- // Look for the Group's root directory. See if we can find it.
-
- If (GroupName = "") Then
- GroupName = "TEST"
- Endif
-
- If (RootPath = "") Then
- RootPath = GetControlDir ()
- RootPath = RootPath + "\" + GroupName
- Endif
-
- If (FileExists (RootPath + "\" + "RETRY.LST")) Then
- Print "Loading Clients from Group Retry List"
- Handle = Open (RootPath + "\" + "RETRY.LST", FILE_READ)
-
- If (Handle != 0) Then
- Do Until EOF (Handle)
- Line = ReadLine (Handle)
- Lines = Lines + 1
- Print "Line ", Lines, " <", Line, ">"
-
- If Trim (Line) != "" Then
- SplitLine = TokenList (Line, "|")
- If Items (SplitLine) > 4 Then
- Print "Adding : ", Line
- AddItem (GroupList, Line)
- Else
- Print "Skipping : ", Line
- Endif
- Else
- Print "Skipping blank line"
- Endif
- Loop
-
- Print "Summary"
- Print Lines, " lines processed"
- If (Items (GroupList) > 0) Then
- Print "Retry List contains ", Items (GroupList), " Clients."
- Else
- Print "Retry List is empty."
- Endif
- Close (Handle)
- Endif
- Else
- Print "Selecting all Clients from Group: ", GroupName
- GroupList = GetGroup (GroupName, "")
- Endif
-
- // Make sure that at least one Client has been found.
-
- If Items (GroupList) > 0 then
-
- // Now, look for any update files.
- // They should be in the Group's root directory.
-
- If (RootPath = "") Then
- RootPath = GetControlDir ()
- RootPath = RootPath + "\" + GroupName
- Endif
-
- If (DirExists (RootPath)) Then
- Print "Update file path : ", RootPath, "\files"
-
- // Look to see if there are any files there...
-
- If (GetFileList (RootPath + "\files\*.*", FileNameList) > 0) Then
- Print Items (FileNameList), " update file(s) found."
- Else
- Print "ERROR: No update files found for Group : ", GroupName
- Print "Script Exiting."
- Goto Summary
- Endif
- Else
- Print "Update file path : ", RootPath, "\", GroupName, " not found!"
- Print "Script Exiting."
- Goto Summary
- Endif
-
- // Execute the following loop on all Clients found.
-
- For Each Member in GroupList
- Trim (Member)
- Print "Processing Client ", Member, "..."
- ClientInfo = TokenList (Member, "|")
-
- // Check the token count. We need 5 of them.
-
- If (Items (ClientInfo) < 5) Then
- Print "WARNING: Insufficient tokens found in line ", Member, ":"
- For Each Token in ClientInfo
- Print Token
- Next
- Else
- Name = GetItem (ClientInfo, 1)
- Address = GetItem (ClientInfo, 2)
- Transport = CInt (GetItem (ClientInfo, 3))
- Location = CInt (GetItem (ClientInfo, 4))
- Network = GetItem (ClientInfo, 5)
-
- Print "Client Information : "
- Print " Name : ", Name
- Print " Address : ", Address
- Print " Transport : ", Transport
- Print " Location : ", Location
- Print " Network : ", Network
-
- // Zero the error count for this Client
-
- ErrorsForThisClient = 0
-
- // If we have a remote network, indicated by Location > 0,
- // then look it up in the Known Remote Networks file.
-
- If (Location > 0) Then
- NetworkDetails = GetRemote (Network, "")
- NetworkInfo = TokenList (NetworkDetails, "|")
- DialNumber = GetItem (NetworkInfo, 3)
-
- // See if we are already dialled to this location
-
- If (DialNumber != LastDialled) Then
- If (LastDialled != "") Then
- Print "Hanging up : ", LastDialled
- Hangup ()
- LastDialled = ""
-
- // I bet we have to wait for a while here...
-
- Wait (10)
- Endif
- Endif
- Else
-
- // This Client is local, not at a remote location. Clear the
- // dial number so we don't try to call it...
-
- DialNumber = ""
-
- // If we are connected to a remote network, hang up.
-
- If (LastDialled != "") Then
- Print "Hanging up : ", LastDialled
- Hangup ()
- LastDialled = ""
- Wait (10)
- Endif
- Endif
-
- // Next, check the Client's transport against the last one
- // we were using, if any. If there is a difference, we have
- // to call SetTransport to change over.
-
- If (Location > 0) Then
- NextTransport = Transport + T_REMOTE
- Else
- NextTransport = Transport
- Endif
-
- If (NextTransport != LastTransport) Then
- Print "Changing transport from : ", LastTransport, " to ", NextTransport
- If (Location > 0) Then
- SetTransport (Transport, T_REMOTE)
- LastTransport = Transport + T_REMOTE
- Else
- SetTransport (Transport)
- LastTransport = Transport
- Endif
- Endif
-
- If (DialNumber != "") Then
- If (Dial (DialNumber, Password)) Then
- LastDialled = DialNumber
- Else
- Print "ERROR: No answer from network : ", Network, " on ", DialNumber
- LastDialled = ""
-
- // Bump the error count for this Client and leave the
- // end of loop retry logic to sort out what to do about it.
-
- DialErrors = DialErrors + 1
- ErrorsForThisClient = ErrorsForThisClient + 1
- Goto LoopEnd
- Endif
- Endif
-
- LogFilePath = RootPath + "\" + Name + ".LOG"
-
- // Attempt to connect to the Client.
-
- If Connect (Name, UserName) then
- Print "Connected to Client ", ClientCount, " ", Name
- AddToLog (LogFilePath, "Connected to Client : " + Name)
-
- // Now, see if we can send the update files.
- // First, check the Client's output path.
-
- OutputPath = GetInstallDir ()
- OutputPath = ">" + OutputPath + "\Files"
-
- If (!DirExists (OutputPath)) Then
- If (MkDir (OutputPath)) Then
- AddToLog (LogFilePath, "Created directory : " + OutputPath)
- Endif
- Endif
-
- // Compare the input and output files to see if we
- // need to update any existing files at the Client
-
- For Each File in FileNameList
- FileComparison = FileCompare (RootPath + "\files\" + File, OutputPath + "\" + File)
-
- // We don't care about file attribute differences,
- // so 0 and 1 mean that both files are the same
-
- If (FileComparison > 1) Then
- If (Copy (RootPath + "\files\" + File, OutputPath)) Then
-
- // 5 means output file not found. Anything else means that the
- // output file existed but was different (not necessarily older).
-
- If (FileComparison = 5) Then
- AddToLog (LogFilePath, "Copied file : " + File)
- FileCopyCount = FileCopyCount + 1
- Else
- AddToLog (LogFilePath, "Updated file : " + File)
- FileUpdateCount = FileUpdateCount + 1
- Endif
- Else
- Print "WARNING: Unable to copy file : ", File, " to Client : ", Name
-
- // Bump the error counts
-
- FileErrors = FileErrors + 1
- ErrorsForThisClient = ErrorsForThisClient + 1
- Endif
- Endif
- Next
-
- Disconnect (Name)
- AddToLog (LogFilePath, "Disconnected from : " + Name)
- ClientCount = ClientCount + 1
- Else
- AddToLog (LogFilePath, "Unable to Connect to Client : " + Name
- ConnectErrors = ConnectErrors + 1
- ErrorsForThisClient = ErrorsForThisClient + 1
- Endif
- Endif
-
- // At the end of the Client loop, we just check whether there
- // were any errors. If there were, then we will need to record
- // the Client's network details for retrying later. These are in
- // the Member string variable.
-
- LoopEnd:
-
- If (ErrorsForThisClient >0) Then
- TotalErrors = TotalErrors + ErrorsForThisClient
- AddItem (RetryList, Member)
- Endif
- Next
-
- // Tidy up any remote connections
-
- If (LastDialled != "") Then
- Print "Hanging up : ", LastDialled
- Hangup ()
- LastDialled = ""
- Endif
-
- // and turn off the dialup transport
-
- If (LastTransport > T_REMOTE) Then
- LastTransport = LastTransport - T_REMOTE
- SetTransport (LastTransport)
- Endif
- Else
- Print "No Clients were found!"
- Endif
-
- // Check for any errors and queue a retry for later.
- // Here, we simply overwrite any old retry list.
-
- If (TotalErrors > 0) Then
-
- // Double-check (run-time error if it's empty)...
-
- If (Items (RetryList) > 0) Then
-
- // Create a new retry list file, overwriting any existing file
-
- If (FileExists (RootPath + "\" + "RETRY.LST")) Then
- Handle = Open (RootPath + "\" + "RETRY.LST", FILE_OVERWRITE)
- Else
- Handle = Open (RootPath + "\" + "RETRY.LST", FILE_CREATE)
- Endif
-
- If (Handle != 0) Then
- For Each Member in RetryList
- Print "Adding : ", Member, " to Retry List"
- WriteLine Handle, Member
- Next
- Close (Handle)
- Endif
- Endif
- Else
- If (FileExists (RootPath + "\" + "RETRY.LST")) Then
- Print "Deleting Retry List"
- Delete (RootPath + "\" + "RETRY.LST")
- Endif
- Endif
-
- // Print a summary
-
- Summary:
- Print "Number of Clients found: ", ClientCount
- Print " Number of files copied: ", FileCopyCount
- Print " Number of files updated: ", FileUpdateCount
- If TotalErrors > 0 Then
- Print "Total Errors:", TotalErrors
- Print "Dial Errors:", DialErrors
- Print "Connect Errors:", ConnectErrors
- Print "File Errors:", FileErrors
- Endif
- End Function
-