#46253 - 2003-10-02 01:46 PM
Online Status & Shutdown
|
DarkFather
Lurker
Registered: 2003-10-01
Posts: 4
Loc: Germany
|
Hi all
I have a little problem with this script... it should work like this:
1. Check the time (script should only work between 10PM-11PM) 2. Check online status 3. Shutdown computers which are online 4. list all online(and offline) computers
the timecheck itself works... but i dont know how to stop the script when it shows the "wrong" time...
the online check works without problems (shutdown should work too... didnt checked this till now)
Next problem is, that i have to check perhaps 100 different IP's... it works like i did it here, but it looks bad...
ah, and this is my first script... and the first thing i ever did with kix ... so i am happy for every assistance i get
code:
$TimeofDay = Val( SubStr(@TIME,1,2) ) Select Case $Timeofday => 6 AND $Timeofday < 22 $timetorun = "error" $m=MessageBox ("Wrong Time",Time) Case $Timeofday >= 22 AND $Timeofday <= 23 $timetorun = "ok" $m=MessageBox ("Time OK",Time) Case 1 $timetorun = "error" $m=MessageBox ("Wrong Time2",Time) EndSelect
$Counter=0 $IP="149.250.16.207"
;If $timetorun="error" ; $Counter="3" ; Else ; $Counter="0" ;EndIf
Do
Shell '%comspec% /c ping -w 1 $IP|find "Timeout" > nul' If @error Shell "%comspec% /e:1024 /c echo $IP Online >> c:\temp\kix\ping.txt" ; Shutdown ("\\$IP","Shutdown in 30 Seconds",30,1,2) Else Shell "%comspec% /e:1024 /c echo $IP Offline >> c:\temp\kix\ping.txt" EndIf $Counter=$Counter+1
If $Counter=0 $IP="149.250.16.207" EndIf
If $Counter=1 $IP="149.250.16.208" EndIf
If $Counter=2 $IP="149.250.16.55" EndIf
Until $Counter=3
Shell "%comspec% /e:1024 /c echo @day @time >> c:\temp\kix\ping.txt"
|
|
Top
|
|
|
|
#46254 - 2003-10-02 01:50 PM
Re: Online Status & Shutdown
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Welcome to the board..
Have a look at the UDF Section of this site. There are a number of Time-Related UDFs to help you along..
Thanks,
Kent
|
|
Top
|
|
|
|
#46256 - 2003-10-02 02:00 PM
Re: Online Status & Shutdown
|
DarkFather
Lurker
Registered: 2003-10-01
Posts: 4
Loc: Germany
|
Thanks Lonkero... this was exactly what i was looking for
code:
$TimeofDay = Val( SubStr(@TIME,1,2) ) Select Case $Timeofday = 22 $timetorun = "ok" $m=MessageBox ("Time OK",Time) Case 1 $timetorun = "error" $m=MessageBox ("Wrong Time",Time) EndSelect
If $timetorun="error" Exit 1 EndIf
the time part works correctly now...
|
|
Top
|
|
|
|
#46257 - 2003-10-02 02:24 PM
Re: Online Status & Shutdown
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
See also the 'ping' and 'shutdown' UDFs. However, much faster would becode:
$TimeofDay = val(split(@TIME,':')[0]) if $$TimeofDay<22 or $TimeofDay>23 exit 0 endif $comps=netview2() for each $comp in $comps if $comp<>@WKSTA $rc=shutdown($comp,'"Shutdown in 30 Seconds',30,1,2) if @error $offline=$offline+1 else $online=$online+1 endif endif next ? 'Computers already offline :'+$offline ? 'Computers online (SHUTDOWN) :'+$online $rc=shutdown(@WKSTA,'"Shutdown in 30 Seconds',30,1,2) exit 0
This will shutdown all computers in the domain including the computer that the script runs from. Use at your own risk. NetView2() is a UDF from the uDF Forum.
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#46260 - 2003-10-02 02:43 PM
Re: Online Status & Shutdown
|
DarkFather
Lurker
Registered: 2003-10-01
Posts: 4
Loc: Germany
|
@sealeopard thats the problem... it should NOT shutdown every computer in our Domain... if i would do this, i would have a real problem
@LLigetfa i use the task scheduler to run it... this is just to be sure that noone can start this script during worktime
Background of this script is that a lot of users dont turn off their PCs at the end of the day... and when they have some programs running which are connected to our fileserver, we can't run our daily Backup correctly... so we have to shutdown every PC, but not the servers...
|
|
Top
|
|
|
|
#46261 - 2003-10-02 02:46 PM
Re: Online Status & Shutdown
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
Improved to exclude certain comps, remove the first three lines if used with Task Scheduler, or keep them as safety measure.
code:
$TimeofDay = val(split(@TIME,':')[0]) if $$TimeofDay<22 or $TimeofDay>23 exit 0 endif $excluded='comp1','comp2','comp3',@wksta $comps=netview2() for each $comp in $comps if ascan($excluded,@WKSTA)=-1 $rc=shutdown($comp,'"Shutdown in 30 Seconds',30,1,2) if @error $offline=$offline+1 else $online=$online+1 endif endif next ? 'Computers already offline :'+$offline ? 'Computers online (SHUTDOWN) :'+$online $rc=shutdown(@WKSTA,'"Shutdown in 30 Seconds',30,1,2) exit 0
[ 02. October 2003, 14:47: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#46262 - 2003-10-02 03:17 PM
Re: Online Status & Shutdown
|
DarkFather
Lurker
Registered: 2003-10-01
Posts: 4
Loc: Germany
|
thanks for your work sealeopard, but your script is still to difficult for me... as i said, i started today with kix ... it takes me like 4 hours to write the little script in my first post ...
next week i have to build a little "test" Domain anyway, perhaps i will try to run your script on this domain
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 696 anonymous users online.
|
|
|