Page 1 of 1 1
Topic Options
#207676 - 2013-09-03 07:50 PM Logic gut check
Tsguy Offline
Getting the hang of it

Registered: 2010-01-18
Posts: 67
Loc: Oregon
Hello all,

I realize there are a number of ways to skin a kix script ;), but I was hoping for a general Logic gut check on a project I'm working on.

The script is using "ComputerinGroup" as a Udf - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=195717

What I'm attempting to do is:

- Determine if the computer running the script is in a domain security group.
- Determine if a file exists on the computer.
- If the computer is in the domain security group, and the file doesn't exist, run a CMD script and then wait for the file to exist.
- The called CMD script will create a file on the computer once it completes that should be the trigger kix is waiting for to continue processing.
- If the computer runs the script, change the reboot flag to 1, so that the comp will be rebooted at script's end.



 Code:
;
CALL '\\Networkserver\Networkshare\ComputerinGroup.udf'
;
$Access2k10 = '\\Networkserver\Networkshare\O2k10-Access.cmd'
$A2k10Check = Exist("c:\scripts\Installed\A2k10.txt")
$MessageHeader = ' Software is being installed to your computer ' 
$Reboot = 0
;
If ComputerinGroup ("Access2k10") AND $A2k10Check = 0 
	MessageBox ("$MessageHeader","               Access 2010 is being installed / upgraded...               ",0,30)
	$Reboot = 1
	RUN $Access2k10
		DO
			Sleep 10
		Until $A2k10Check = 1
EndIf
;
If $Reboot = 1 
	Shutdown ("", "The upgrades performed on your computer require a reboot, that will occur in 20 seconds.", 20, 1, 1) 
Else 
Exit


This is not the full script as there are a number of other moving parts in it. But this is the general premise that I'm looking to accomplish with this particular section. What I'm unclear on most is if the Do / Until and the file existence checks make sense as they are currently. My first time looping...(that sounds a bit odd i know)

thanks for any advice,

Lan

Top
#207678 - 2013-09-03 09:46 PM Re: Logic gut check [Re: Tsguy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
You're gonna loop forever!

Put the "Exist" command inside your do loop, like
 Code:
Do
  Sleep 10
  $Count = $Count + 1
Until Exist('some\file') And $Count > 18
I'd also include some kind of counter to prevent a crashed CMD file from hanging the Kix script forever. The example above waits for 180 seconds (18 loops of 10 seconds) before exiting. You can check for a timeout if $Count >= 18.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207679 - 2013-09-03 10:09 PM Re: Logic gut check [Re: Glenn Barnas]
Tsguy Offline
Getting the hang of it

Registered: 2010-01-18
Posts: 67
Loc: Oregon
Hi Glenn \:\)

Thank you for your input, as the exist checking was also something I was a bit unclear on. Modified code below.

 Code:
;
CALL '\\Networkserver\Networkshare\ComputerinGroup.udf'
;
$Access2k10 = '\\Networkserver\Networkshare\O2k10-Access.cmd'
$A2k10Check = 'c:\scripts\Installed\A2k10.txt'
$MessageHeader = ' Software is being installed to your computer ' 
$Reboot = 0
;
If ComputerinGroup ("Access2k10") AND NOT EXIST ($A2k10Check) 
	MessageBox ("$MessageHeader","               Access 2010 is being installed / upgraded...               ",0,30)
	$Reboot = 1
	RUN $Access2k10
		DO
			Sleep 10
		Until EXIST ($A2k10Check)
EndIf
;
If $Reboot = 1 
	Shutdown ("", "The upgrades performed on your computer require a reboot, that will occur in 20 seconds.", 20, 1, 1) 
Else 
Exit


You also have an excellent point about possible forever loop if there's a failure in the called CMD. However, I'm closing my eyes, and ignoring that potential problem for now.

Top
#207680 - 2013-09-03 10:46 PM Re: Logic gut check [Re: Tsguy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
The "Exist" is one-time/immediate, so it has to run in the loop. Just so long as you are aware of theh potential for issues if the CMD fails or does not generate the flag file.

Also - creating flag files, especially those that remain on the computer for long periods, is not a good method. With Kix, you should be able to tell if an application's registry key is present - if not, run the installer as a child process. When the child creates the flag, Kix can continue by deleting the flag file and then rebooting. The next time the script runs, it will detect the app's reg key.

Another method is to eliminate the flag file entirely and use SHELL to run the installer CMD file - Kix will wait for it to complete.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207681 - 2013-09-03 11:56 PM Re: Logic gut check [Re: Glenn Barnas]
Tsguy Offline
Getting the hang of it

Registered: 2010-01-18
Posts: 67
Loc: Oregon
Again, more great points Glenn.

The flag files; yes, it's an issue, but one we're trying to mitigate a bit in our own way, and at this point there are a number of projects wrapped into the framework. We decided not to pursue the concept unless a clear use design was implemented, documented, followed, and maintained. Reg keys were brought up as an option in the design, but the format we're in won out for other reasons.

I had considered Shelling out the call to CMD when I started on this project (and may still do so). At the time of writing, I liked the idea of the kix script waiting on the flag to appear.

ty again for your insight Glenn,

Lan

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.055 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org