#168146 - 2006-09-20 11:53 PM
filesize comparison no working?
|
Lucid
Fresh Scripter
Registered: 2006-09-20
Posts: 11
|
Hello All,
I'm working on my very first kix script and running into trouble. Essentially we have an update to a program we use in the office that simply requires an MDE file to be replaced on the user's workstation. Since the environment is not managed very well I'm trying to put in some checks to make sure the file that needs to be replaced is actually there. Since this script will run at login for a few days as users come in and out of the environment I want to make sure it doesn't keep replacing the file for users that have already had it replaced. My newb way to do this was to do a filesize comparison and then if its different to replace the file. I also wanted to create a log file of what's going on. So after all that, here is the script I came up with (specific paths and company info snipped):
$wrkFile="[snip]balaboss.mde" $ServFile="[snip]balaboss.mde" $Logfile = "c:\" + @month + @mdayno + ".log"
If Exist ($wrkFile) $wrksize=getfilesize($wrkfile) $servsize=getfilesize($servfile) IF $wrksize<>$serversize copy $servfile "[snip]balaboss.mde" $operation = "file replaced" else $operation = "file left alone" endif else $operation = "file not found" endif If Open (1,$logfile,5) = 0 Writeline (1, @wksta + " / " + @userid + @CRLF + "Workstation File Size = " + $wrksize + " " + "Server File Size = " + $servsize + @CRLF + "Result = " + $operation + @CRLF + @CRLF+ @CRLF) Close(1) Endif
The trouble that I am running into is that it appears to still be copying the file over even when its the same size (at least that's what my $operation variable is showing). Here's an part of the output log for 3 attempts (first with the file missing from the workstation, second with the old file where it should be, and third after the file has been updated):
workstation / username Workstation File Size = Server File Size = Result = file not found
workstation / username Workstation File Size = 46123008 Server File Size = 46630912 Result = file replaced
workstation / username Workstation File Size = 46630912 Server File Size = 46630912 Result = file replaced
Can anyone point me to where I'm going wrong. I'm also open to revamping the whole thing if anyone has a better suggestion on how to code it so the it checks if the file exists and is different from the new one (file size was the first thing I could come up with).
Many thanks in advance.
|
|
Top
|
|
|
|
#168147 - 2006-09-21 12:15 AM
Re: filesize comparison no working?
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Code:
$servsize=getfilesize($servfile) IF $wrksize<>$serversize
I would like to recommend you a header in your scripts like Code:
If NOT @LOGONMODE Break On EndIf Dim $RC $RC = SetOption("Explicit","On") ; <-- This will help you $RC = SetOption("NoVarsInStrings","On") $RC = SetOption("NoMacrosInStrings","On") $RC = SetOption("WrapAtEOL","On")
|
|
Top
|
|
|
|
#168149 - 2006-09-21 09:20 AM
Re: filesize comparison no working?
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Do you mean Code:
$RC = RedirectOutput(@SCRIPTDIR + "\RedirectOutput.txt",1)
It does not affect RedirectOutput because a text file is not limited to 80 columns like an ancient screen in DOS. Lines are just typed to the end. I use it for output on screen, to avoid overtyping on the same line.
|
|
Top
|
|
|
|
#168152 - 2006-09-21 08:20 PM
Re: filesize comparison no working?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Not for me, got tired of that so now the logon script changes it for me during logon to any machine I log onto.
|
|
Top
|
|
|
|
#168153 - 2006-09-21 08:21 PM
Re: filesize comparison no working?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
oh... and guess I should RTM more often. It is right there in the manual.
Quote:
Enables/disables wrapping of console output at the end of a line
Otay, have added it to my header for scripts.
|
|
Top
|
|
|
|
#168154 - 2006-09-21 10:23 PM
Re: filesize comparison no working?
|
Lucid
Fresh Scripter
Registered: 2006-09-20
Posts: 11
|
Stupid newb mistake. I will fix the error and test it out and get back to you. Can you explain what this "header" that you recommend does, or point me to a place that will explain it.
Thanks for your help.
|
|
Top
|
|
|
|
#168156 - 2006-09-22 12:27 AM
Re: filesize comparison no working?
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Read the Kix2010.doc. It is not that big and it contains all the answers. Code:
If NOT @LOGONMODE Break On EndIf
If you break a KiX script, per default KiXtart will log off your computer. This is OK for login scripts. But for other purposes, most of the time this behaviour is unwanted. Take a look at the vivid discussion: Break On should be the deafult. Code:
Dim $RC $RC = SetOption("Explicit","On")
If you do not Dim a variable, it is global. I prefer local variables to avoid confusion. The Explicit option forces to declare variables. Code:
$RC = SetOption("NoVarsInStrings","On")
If a $-sign is used between quotes, KiX tries to translate it together with the trailing chars to a variable. You would have to double the $ ($$) to show it is not a var. Only exception is when the $ is at the last place of a string, e.g. "\\Server\HiddenShare$" or "This is a $ symbol". Setting the NoVarsInStrings option makes that a $ between quotes is always a part of a string. Code:
$RC = SetOption("NoMacrosInStrings","On") Code:
If @ is used between quotes, KiX tries to translate it,together with the trailing chars, to a macro. you would have to double the @ (@@) to avoid it. Setting the NoMacrosInStrings option on does just what is says: No Macros In Strings. Code:
$RC = SetOption("WrapAtEOL","On")
If screen output is wider then the character width of a command window, the same line is overwritten. The WrapAtEOL option adds a crlf to the character at the end of the line.
|
|
Top
|
|
|
|
#168157 - 2006-09-22 04:23 AM
Re: filesize comparison no working?
|
Lucid
Fresh Scripter
Registered: 2006-09-20
Posts: 11
|
Thank you kindly for finding the flaw in my script and for explaining the header options to help improve my future endevors. I have fixed the script and it works great.
Just one last question, I seem to get a line with "00" in the command prompt window after my script completes before I get a prompt back. It doesn't seem to keep the script from running properly, but I'm wondering if it indicates a problem I should be concerned with.
|
|
Top
|
|
|
|
#168159 - 2006-09-22 05:34 AM
Re: filesize comparison no working?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 978 anonymous users online.
|
|
|