Page 1 of 1 1
Topic Options
#129874 - 2004-11-18 06:02 PM IF statement to check the hostname
mattl72 Offline
Lurker

Registered: 2004-11-18
Posts: 2
Hi, I'm new to kixtart but I think what I'm trying to do should be pretty easy. Basically, I just want to check to see if a hostname or NETBIOS name matches (there's actually 3 computers I need to check for), and if so - do nothing, but run an executable for everyone else. I'm guessing it will look something like this:

If HOSTNAME = workstation1 or workstation2 or workstation3
Do nothing
ELSE
Run executable
ENDIF

I'm not sure what the syntax is though. Also, how do I launch an executable from within the script?

Any help would be greatly appreciated.

Thanks,
Matt

Top
#129875 - 2004-11-18 06:11 PM Re: IF statement to check the hostname
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
This would be the most straight-forward way ...

Code:


BREAK ON
IF @WKSTA <> "Jooel" AND @WKSTA <> "Shawn" AND @WKSTA <> "Ron"
?"run something..."
ENDIF
EXIT 0




If your planning on having many workstations in this list, or if you plan on changing the list going-forward, could suggest other more gracefull ways of doing this.

-Shawn

Top
#129876 - 2004-11-18 07:29 PM Re: IF statement to check the hostname
mattl72 Offline
Lurker

Registered: 2004-11-18
Posts: 2
Thanks for your quick reply - it worked great. Its just going to be 3 workstations. Would it be better to do it with CASE statements?
Top
#129877 - 2004-11-18 07:35 PM Re: IF statement to check the hostname
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
You could use a Select Case, but probably not the best solution.

Shawn's method should work, and here is another way as well.

Code:
Dim $ComputerList
$ComputerList = Split("Jooel|Shawn|Ron","|")
If AScan ($ComputerList, @WKSTA)>=0
;Do nothing
Else
SHELL '%COMSPEC% /C "IPCONFIG /registerdns" >NUL 2>NUL'
EndIf



Top
#129878 - 2004-11-18 07:43 PM Re: IF statement to check the hostname
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Eh, waddup with the Split()? Couldn't find a half dozen more functions to add to the soup?

$ComputerList = 'Jooel','Shawn','Ron','Les'
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129879 - 2004-11-18 07:44 PM Re: IF statement to check the hostname
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja, but because your excluding hostnames and because it involves multiple conditions, I would suggest that a SELECT statement would be over-kill and not pratical anyways ... it would end-up just looking like the IF state above anyways, with more lines of un-necessary code ... like this:

Code:

SELECT
CASE @WKSTA <> "Jooel" AND @WKSTA <> "Shawn" AND @WKSTA <> "Ron"
; do something
CASE 1
; do nothing
ENDSELECT



You can't break each case out into its own case statement, because you need to check for all three hostnames at once. Anyways, if this is just a quick-hitter thing would suggest you stick with the above or DOC's code.

-Shawn

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 (Allen) and 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.049 seconds in which 0.022 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