Page 1 of 1 1
Topic Options
#76270 - 2003-08-07 07:46 PM Emergency Patch Distribution System Example
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The following script demonstrates a way to distribute a patch to all computers inside a domain from a central location. Ideally, the script would run as a scheduled task under domain administrative privileges at night. The patch would be provided with command-line arguments that automatically install the patch and reboot the system. Optionally, a list of computers, e.g. servers, can be excluded for the patch distribution

This example will only open notepad and load a potentially existing file and is for demonstration purposes only.

Requires the updated ScheduleTask v1.3 UDF

code:
; uses the COMNetView() and ScheduleTask() v1.3 UDFs

break on
dim $iRC

; set restrictive script settings
$iRC=SETOPTION('Explicit','on')
$iRC=SETOPTION('NoVarsInStrings','on')
$iRC=SETOPTION('WrapAtEOL','on')

dim $asComputers, $sComp, $sExcluded
dim $sTSName,$sTSDate,$sTSTime,$sTSType,$sTSCmd,$sTSPrms

; do not run the scheduled command on these computers
$sExcluded='server1','server2','server3','server4'

$asComputers=COMNetView()
if ubound($asComputers)+1
? 'Computers in domain '+@DOMAIN+' = '+(ubound($asComputers)+1)
else
? 'Error '+@ERROR+' - '+@SERROR
? 'Unable to retrieve list of computers in domain '+@DOMAIN
endif

$sTSName='example.job'
$sTSDate='TODAY'
$sTSTime='NOW'
$sTSType='ONCE'
$sTSCmd='notepad'
$sTSPrms='%TEMP%\test.txt'

for each $sComp in $asComputers
if ascan($sExcluded,$scomp)=-1
? 'Scheduling task for '+$sComp
$iRC=scheduletask($sTSName,$sComp,$sTSDate,$sTSTime,$sTSType,$sTSCmd,$sTSprms)
? 'Error '+@ERROR+' - '+@SERROR
else
? $sComp+' excluded from update'
endif
next

exit 0



[ 07. August 2003, 20:37: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#76271 - 2003-08-07 08:12 PM Re: Emergency Patch Distribution System Example
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Doh, I didn't download JT.EXE. [Roll Eyes]

But now I have it working, first time I have used JT and the Scheldue UDF.

Looks good.

Thanks

[ 07. August 2003, 20:36: Message edited by: Richard Farthing ]

Top
#76272 - 2003-08-07 08:36 PM Re: Emergency Patch Distribution System Example
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You are using an outdated ScheduleTask() UDF. Grab the new version here: SCHEDULETASK() - Schedules a task on any computer using the Task Scheduler
_________________________
There are two types of vessels, submarines and targets.

Top
#76273 - 2003-08-07 11:09 PM Re: Emergency Patch Distribution System Example
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Working well, but how would I make the job "Run Now", instead of running at the next minute.

In the book it says "/RJ", but where would I put that, everything I have tried makes the script fail.

Thanks

Top
#76274 - 2003-08-07 11:13 PM Re: Emergency Patch Distribution System Example
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The RUN NOW is actually one minute ahead of local time. It is identical with the SOON.EXE behavior. This compensate for time drifts across computers. You cannot execute a task faster than one minute ahead as the time resolution for scheduling tasks is also one minute.

For the /RJ to work, you will need to load an existing task via /LJ into memory first. However, if I understand the documentation correctly, you would then run the task on the local computer, maybe even under the current user's credentials.

[ 07. August 2003, 23:17: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#76275 - 2003-08-08 12:26 AM Re: Emergency Patch Distribution System Example
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I would also suggest that this is for a SMALL size business.

A medium size or large enterprise network with thousands of systems, would not be prudent to run any installation against one install server.
Doing so would basically cause a Denial Of Service attack on that system.

The idea and methodology though is of value overall.

Top
#76276 - 2003-08-08 12:44 AM Re: Emergency Patch Distribution System Example
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Jens to get RunNow (/RJ) to work I have added this into the UDF just before it shells out to '$Shellcmd' for the final time.

code:
If $Time = 'Now'
$shellcmd = $shellcmd+ ' /RJ'
EndIf

What is the point of having a time of "now" when it will actually run 60 seconds in the future, so I have said that if Time = Now, then Run job Now (/RJ).

Works for me, might be something worth thinking about, not saying that you should change the UDF, but it is up to you.

One other thing, when this is running on a remote PC, it is hidden, but the "$shellcmd = $shellcmd+ ' Hidden=0'" is set to 0, any ideas.

It is running in the background, but not being displayed on screen, not a problem as I wouldn't want the user to see what is being installed, but just wanted to know if it can be displayed on screen.

Thanks

[ 08. August 2003, 10:47: Message edited by: Richard Farthing ]

Top
#76277 - 2003-08-08 08:18 PM Re: Emergency Patch Distribution System Example
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If the useraccount is logged into the computer under which the task is run, you will be able to see the task running. Good for debugging purposes.

Doc: Totally agree with you that it might not be prudent to run this in a larger domain. However, one can always beef up the patch distribution by implementing some kind of load-balancing, e.g. pulling the patch form the logon server that has ben used to validate the user account.
_________________________
There are two types of vessels, submarines and targets.

Top
#76278 - 2003-08-08 08:27 PM Re: Emergency Patch Distribution System Example
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Since it is task scheduled, one could always stagger them instead of them all running 'Now'.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#76279 - 2003-08-08 08:41 PM Re: Emergency Patch Distribution System Example
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or one copies the files to the local machine, runs the script, and deletes the files afterwards.
_________________________
There are two types of vessels, submarines and targets.

Top
#76280 - 2003-08-08 10:54 PM Re: Emergency Patch Distribution System Example
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I don't disagree that there are not otherways around it.

Just wanted to point out that one should not just blindly perform this task. I would really hope that any large network would already have an Admin on board that knows this.... but hey! you never can tell. [Eek!]

Top
#76281 - 2003-08-08 10:59 PM Re: Emergency Patch Distribution System Example
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
That's why it only opens Notepad on the target systems. [Wink]

And, yes, it's supposed to only illustrate the framework. I just though I'll post this due to that latest Microsoft patch that suddenly everybody wanted to install right away.

One would definitely create a more advanced server or client script around this. For example, one could copy the files to the clients during daytime anfd schedule the actual patch install and reboot for the night.
_________________________
There are two types of vessels, submarines and targets.

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 988 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.033 seconds in which 0.013 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