Page 1 of 1 1
Topic Options
#76312 - 2003-08-09 11:46 PM Wake-on-LAN combined with SUS, using KiXtart scripts
Eduard Offline
Fresh Scripter

Registered: 2003-08-09
Posts: 16
Loc: Amsterdam
Hi,

At our office, we are using Microsoft’s SUS-server (Software Update Services), which automatically employs critical and security updates to Windows 2000 client PC’s.
The common setup of SUS often requires users to reboot their PC a few minutes after starting-up, which can be an annoyance when they are busy. Therefore I figured out how to use SUS in combination with a Wake-on-LAN function.
For this, I made two KiXtart scripts.
Both because some of you might be interested in how I did set this up, and because I (still being a novice regarding scripting) would be interested in any suggestions for improvements, I am posting these scripts in this forum.
For a complete story of how I did set this up, please take a look at the following homepage:
http://www.gironet.nl/home/evbalen/index.htm

The scripts are running under KiXtart version 4.21
This are the two scripts:

sustatus.kix
code:
;This script checks for the status of SUS Auto Update on shutdown,
;sets the WOL-trigger in a daily log file, taking into account weekends,
;and writes the AU-status to a log file.
IF @WDAYNO > 4
$Day = @YDAYNO + 8 - @WDAYNO
ELSE
$Day = @YDAYNO + 1
ENDIF
$AUState = READVALUE("HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update","AUState")
IF $AUState = 5
OPEN(1,"\\server-name\WOL$\" + @YEAR + $Day + ".log",5)
WRITELINE(1, @IPADDRESS0 + "," + @ADDRESS + @CRLF)
ENDIF
OPEN(2,"\\server-name\WOL$\sustat.log",5)
WRITELINE(2, @DATE + "," + @TIME + "," + $AUState + "," + @IPADDRESS0 + "," + @WKSTA + @CRLF)

The result of this script is a daily log file, named like "yearday.log" (for example 2003203.log).
These logs contain a list of computers that have to be started at that day.
It is in the form: "IP-address,MAC-address" on each line.
"$Day" is a variable that ensures that no startups are scheduled on Saturdays or Sundays.
"WOL$" is a share on the server where the logs are stored. Note that, because the local system account runs the script at shutdown, this share has to be read/write accessible to "Everyone".
"sustat.log" is an optional additional log file to log the status of every computer at every shutdown.

wol.kix
code:
;This script reads the daily log file for today,
;starts the respective PC's, and logs this action.
OPEN(1,"\\server-name\WOL$\suswol.log",5)
IF OPEN(2,"\\server-name\WOL$\" + @YEAR + @YDAYNO + ".log",2) = 0
$PC = READLINE(2)
WHILE @ERROR = 0
$MAC = RIGHT($PC,12)
$IP = VAL(LEFT(RIGHT($PC,16),3))
RUN "poweroff.exe wol -ip 192.168.0.$IP -subnet 255.255.255.0 -mac $MAC"
WRITELINE(1, @DATE + "," + @TIME + "," + $PC + @CRLF)
SLEEP 1
$PC = READLINE(2)
LOOP
ENDIF

The result of this script is, that all computers that are listed in the daily log file for today, are sent a magic packet by PowerOff, to initiate a Wake-on-LAN.
"suswol.log" is an optional additional log file to log all Wake-on-LAN instances.
"$PC" is a variable containing a line from the daily log file.
"$MAC" is a variable containing the computer’s MAC-address.
"$IP" is a variable containing the last octet of the computer’s IP-address.
The SLEEP function ensures that not all computers are started at the same moment, to preclude a sudden peak in power consumption.

Any thoughts about this?

Thanks,

Ed

Top
#76313 - 2003-08-10 05:01 PM Re: Wake-on-LAN combined with SUS, using KiXtart scripts
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Do A search on this board for Remote Execution Manager
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#76314 - 2003-08-10 07:55 PM Re: Wake-on-LAN combined with SUS, using KiXtart scripts
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or take a look at KiXtart Systems Management Server (Part II, The Server) , which is utilizing WOL.
_________________________
There are two types of vessels, submarines and targets.

Top
#76315 - 2003-08-15 11:05 AM Re: Wake-on-LAN combined with SUS, using KiXtart scripts
Eduard Offline
Fresh Scripter

Registered: 2003-08-09
Posts: 16
Loc: Amsterdam
Thank you Radimus and sealeopard.
Both Remote Execution Manager and KiXtart Systems Management Server are very impressive applications of KiXtart. I had no idea that this would be possible!

But, going back to my own scripts, do you consider this to be a good way to solve this particular problem? It does work, but maybe I forgot something, and it can be improved?

Thanks,
Ed

Top
#76316 - 2003-08-15 11:28 AM Re: Wake-on-LAN combined with SUS, using KiXtart scripts
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
well...
to make it simpler, you don't need a daily log. Just a current one.

do a simple writeprofilestring($logfile,$austate,$ip,$mac) into a single file... the user will have that updated everytime they log in and unless you are very short of IP addresses the ip/mac addresses will never change anyway

the WOL script could be modified in the same way, to use
for each $comp in split(readprofilestring($logfile,'5',''),chr(10)) (or something similar, whatever the exact syntax is)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#76317 - 2003-08-16 04:52 PM Re: Wake-on-LAN combined with SUS, using KiXtart scripts
Eduard Offline
Fresh Scripter

Registered: 2003-08-09
Posts: 16
Loc: Amsterdam
Thanks again Radimus.

I think I understand the concept behind your suggestion.
The sustatus-script will maintain one central ini file in which the SUS-status of every PC is logged at shutdown.
The wol-script will read this ini file every morning, and will wake all PC’s with a status of “5”.
Yes, I can see that this will be a simplification, getting rid of the date dependency.

Working with ini files is new for me. I am going to look into this later this weekend.

Ed

Top
#76318 - 2003-08-17 08:10 PM Re: Wake-on-LAN combined with SUS, using KiXtart scripts
Eduard Offline
Fresh Scripter

Registered: 2003-08-09
Posts: 16
Loc: Amsterdam
OK, I think I have a working version using WRITEPROFILESTRING and READPROFILESTRING.
Thanks again Radimus, for pointing me to this.

See the two new versions of the scripts below:
sustatus.kix
code:
 
;2003-08-17, sustatus.kix version 2.0, created by Ed van Balen.
;This script checks for the status of SUS AutoUpdate on shutdown,
;writes the AU-status to a cumulative log file,
;and sets the WOL-trigger in an initialization file if the AU-status = ”5” (Install pending).

$AUState = READVALUE('HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update','AUState')
OPEN(1,'\\server-name\WOL$\sustat.log',5)
WRITELINE(1,@DATE+','+@TIME+','+$AUState+','+@WKSTA+@CRLF)
CLOSE(1)
IF $AUState <> 5
$AUState = ''
ENDIF
WRITEPROFILESTRING('\\server-name\WOL$\suswol.ini','SUSWOL',JOIN(SPLIT(@IPADDRESS0,' '),'')+@ADDRESS,$AUState)

wol.kix
code:
 
;2003-08-17, wol.kix version 2.0, created by Ed van Balen.
;This script reads the WOL-trigger ini file, starts the applicable PC's,
;and writes this action to a cumulative log file.

OPEN(1,'\\server-name\WOL$\suswol.log',5)
FOR EACH $PC IN SPLIT(READPROFILESTRING('\\server-name\WOL$\suswol.ini','SUSWOL',''),CHR(10))
$IP = LEFT($PC,LEN($PC)-12)
$MAC = RIGHT($PC,12)
IF $MAC > 0
RUN 'poweroff.exe wol -ip $IP -subnet 255.255.255.0 -mac $MAC'
WRITELINE(1,@DATE+','+@TIME+','+$MAC+','+$IP+@CRLF)
SLEEP 1
ENDIF
NEXT

More background info can temporarily be found here: SUSWOL version 2 .

I had to fiddle a little with the WRITEPROFILESTRING parameters to get it working.
The IF / ENDIF sequence in the wol.kix script appeared to be necessary because the last output from SPLIT(READPROFILESTRING) is always an empty line, and PowerOff cannot handle that.

Ed

Top
Page 1 of 1 1


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

Who's Online
0 registered and 895 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.11 seconds in which 0.087 seconds were spent on a total of 12 queries. Zlib compression enabled.

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