Page 1 of 1 1
Topic Options
#46253 - 2003-10-02 01:46 PM Online Status & Shutdown
DarkFather Offline
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 [Smile] ... so i am happy for every assistance i get [Smile]

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 Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#46255 - 2003-10-02 01:53 PM Re: Online Status & Shutdown
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
stop the script?
what about just saying:
exit 1

this:
Case $Timeofday >= 22 AND $Timeofday <= 23

is actually just the same as:
Case $Timeofday = 22

as you only take the our part.
_________________________
!

download KiXnet

Top
#46256 - 2003-10-02 02:00 PM Re: Online Status & Shutdown
DarkFather Offline
Lurker

Registered: 2003-10-01
Posts: 4
Loc: Germany
Thanks Lonkero... this was exactly what i was looking for [Smile]

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 Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also the 'ping' and 'shutdown' UDFs. However, much faster would be
code:
$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
#46258 - 2003-10-02 02:29 PM Re: Online Status & Shutdown
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If the script needs to run at 10PM, why not schedule it with task scheduler. Then all you need to do is exit the script at 11PM.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#46259 - 2003-10-02 02:40 PM Re: Online Status & Shutdown
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Actually, my example would exit automatically as the computer runnign the script will shutdown, too, once all other computers have been sent the shutdown signal.

However, one will need to filter out servers that are supposted to run 24/7, if they exist in that particular domain.
_________________________
There are two types of vessels, submarines and targets.

Top
#46260 - 2003-10-02 02:43 PM Re: Online Status & Shutdown
DarkFather Offline
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 [Big Grin]

@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 Offline
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 Offline
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 [Smile] ... it takes me like 4 hours to write the little script in my first post [Razz] ...

next week i have to build a little "test" Domain anyway, perhaps i will try to run your script on this domain [Smile]

Top
#46263 - 2003-10-02 03:21 PM Re: Online Status & Shutdown
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Go through the script line by line, look up each command/function in the KiXtart Manual, and look up NetView2() in the UDF Forum. The script is very straight-forward, and doesn't contain any fancy stuff.

For fancy stuff look up any of the KiXgolf tournaments [Big Grin]

[ 03. October 2003, 16:20: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

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
0 registered and 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.064 seconds in which 0.027 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