Page 1 of 1 1
Topic Options
#201511 - 2011-02-07 05:28 PM Pull data from another kixtart script
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I have my inital script that is running. It then needs to reach out to grab some data from another script. This is what i have, can someone explain why this is not working?

 Code:
Break on

;Setting up the different variables
Dim $Debug
Dim $server

$Location = ('\\server3\apps\newcomputer\location.kix')

Call '$Location'

? "What server am i pulling applciations from?"
? $Server


Second Script
 Code:
Break on

;Which subnet is the machone on? 
$y=SubStr( @IPADDRESS0, 1, 11)
     Select
       Case $y=" 10.111.  1"
	   $Server = 'Server1'
       Case $y=" 10. 11.100"
	   $Server = 'Server1'
      Case 1
	   $server = 'Server3'
End select

End


I was under the impression that if i "Dimmed" the variable that would make it run across all scripts, thus holding the value.
_________________________
Where ever you go, there you are.

Top
#201512 - 2011-02-07 05:31 PM Re: Pull data from another kixtart script [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
Pretty much the location script will be a repository of subnets = server. Just so i don't have to keep redoing all of my scripts when a location changes.
_________________________
Where ever you go, there you are.

Top
#201514 - 2011-02-07 05:34 PM Re: Pull data from another kixtart script [Re: Tesdall]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
If you declare it with the Global command, then it would be available to all scripts within the current kixtart session. DIM simply declares it locally.
Top
#201515 - 2011-02-07 05:35 PM Re: Pull data from another kixtart script [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Also..Call is not a function, its a command, so the () is not needed around the $Location variable set.
Top
#201516 - 2011-02-07 05:41 PM Re: Pull data from another kixtart script [Re: ShaneEP]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I removed the Dim $server and the () around the $location. But the script still will not show me the ? $Server. Reading the manual the global variable is just '$Server = server3'. So when the second kix script runs it does not pull the information back in.

Is it because the call command kicks it out to a second session? What would i use to keep it in the same session?


Edited by Tesdall (2011-02-07 05:41 PM)
_________________________
Where ever you go, there you are.

Top
#201517 - 2011-02-07 05:44 PM Re: Pull data from another kixtart script [Re: Tesdall]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
There were a couple of other syntax problems (like the END at the end of script 2). The below code works for me...

 Code:
Break on
Global $server

$Location = '\\server3\apps\newcomputer\location.kix'
Call $Location

? "What server am i pulling applciations from?"
? $Server

get $

location.kix
 Code:
Break on
$y=SubStr(@IPADDRESS0, 1, 11)
     Select
       Case $y=" 10.111.  1"
	   $Server = 'Server1'
       Case $y=" 10. 11.100"
	   $Server = 'Server1'
       Case $y="192.168.  1"
	   $Server = 'Server17'
      Case 1
	   $server = 'Server3'
Endselect

Top
#201518 - 2011-02-07 05:49 PM Re: Pull data from another kixtart script [Re: ShaneEP]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
whats the get $ for at the bottom of the first bit of code?
_________________________
Where ever you go, there you are.

Top
#201519 - 2011-02-07 05:55 PM Re: Pull data from another kixtart script [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I did the things you updated in the code, but it still will not display the ? $server. Any ideas?

 Code:
Break on

;Setting up the different variables
Global $Server
Dim $Debug

$Location = '\\server3\apps\newcomputer\location.kix'

Call $Location

? "What server am i pulling applciations from?"
? $Server


 Code:
Break on
$y=SubStr( @IPADDRESS0, 1, 11)
     Select
       Case $y=" 10.111.  1"
	   $Server = 'server11'
       Case $y=" 10. 11.100"
	   $Server = 'server1'
      Case 1
	   $server = 'server3'
End select


Edited by Tesdall (2011-02-07 05:56 PM)
_________________________
Where ever you go, there you are.

Top
#201520 - 2011-02-07 07:18 PM Re: Pull data from another kixtart script [Re: Tesdall]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Current grade would be "C-", mostly because you have data in your code. Bad idea.. Every time you edit the "data" you have the chance to screw up your code.

Data should be in a data file, separate from your code. Using an INI file, similar to:
 Code:
[SUBNET_LOOKUP]
10.11.1.0/24=Server1
10.11.2.0/24=Server2
10.0.0.0/8=Default_Server
you could use EnumINI to return an array of network/mask values. Note that the last entry is a network-wide default. You can specify any size network with this method, not just /24.

Using IsInSubnet(), you could pass the local IP address and the array of network addresses and know precisely which subnet your host was in. Here's some pseudo-code:
 Code:
; This loads an array of W.X.Y.Z/mask network ranges
$aNetworks = EnumIni('\\server\share\subnets.ini', 'SUBNET_LOOKUP') ; load subnet table from common location
; Get my IP address in normalized (no spaces) format
$MyIP = Join(Split($IPADDRESS0, ' '), '')                           ; remove spaces
; Pass IP and network table to UDF, returning an array of 0/1 values. 
; If the table is defined in most to least specific order, the first 
; value that is set represents the network subnet where the host resides
$aNetwork = IsInSubnet($MyIP, $aNetworks)                           ; get network ID (array element)
; find the first "1" in the array returned (may required additional args)
$Net = AScan($aNetwork, 1)                                          ; get first network that host is a member of
; Using the element returned above, get the value to read from the INI file
$Network = $aNetworks($Net)                                         ; return the network/mask for lookup
; Read the server name from the central INI file
$Server = ReadProfileString('\\server\share\subnets.ini', 'SUBNET_LOOKUP', $Network) ; lookup the server name for this network
In this manner, only the central INI data file changes. Once you write and test your code, you never touch it again.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#201521 - 2011-02-07 07:20 PM Re: Pull data from another kixtart script [Re: Tesdall]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
The 'Get $' is just a way to pause the console until a key is pressed. the $ is just a dummy variable to store the keypress in. That way it allows you to see what is being displayed.

I would suggest adding some ?'s in there to verify that the second script is indeed being run, and that the expected IP is being parsed. Try something like this...

 Code:
? "Second script successfully called"
Break on
$y=SubStr( @IPADDRESS0, 1, 11)
? $y
Select
   Case $y=" 10.111.  1"
      $Server = 'server11'
   Case $y=" 10. 11.100"
      $Server = 'server1'
   Case 1
      $server = 'server3'
Endselect


ALSO...I just noticed...You still had a space in the EndSelect line in script 2.

Top
#201522 - 2011-02-07 07:39 PM Re: Pull data from another kixtart script [Re: Glenn Barnas]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
Thanks for the grade, at least its passing.

I see what your saying about the data in a data file, but i have never written an INI file in my life, just edited them (printer drivers).

That is along the lines of what i was trying to accomplish by starting a new script to get the data.
_________________________
Where ever you go, there you are.

Top
#201523 - 2011-02-07 07:44 PM Re: Pull data from another kixtart script [Re: ShaneEP]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
Thanks for the help, i put in a few ? and found that it was indeed running. I made a few spelling mistakes and closed the endselect. It all seems to be working now.
_________________________
Where ever you go, there you are.

Top
#201524 - 2011-02-07 07:52 PM Re: Pull data from another kixtart script [Re: Glenn Barnas]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
Im getting the following error message on the code you have below:

 Code:
ERROR : expected ')'!
Script: \\server3\apps\Newcomputer\Locations.kix
Line  : 16


Line 16 is:
 Code:
$aNetworks = EnumIni('\\usserve3\apps\Newcomputer\Locations.ini', 'SUBNET_LOOKUP') ; load subnet table from common location



Edited by Tesdall (2011-02-07 08:21 PM)
_________________________
Where ever you go, there you are.

Top
#201527 - 2011-02-07 10:41 PM Re: Pull data from another kixtart script [Re: Tesdall]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
And you did copy the EnumINI UDF into your script somewhere?

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=135385

Top
#201528 - 2011-02-07 10:42 PM Re: Pull data from another kixtart script [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Also you posted this line earlier, just in case you were still having problems with it. There was a $ instead of @ for the ipaddress0 macro.

$MyIP = Join(Split($IPADDRESS0, ' '), '')

should be...

$MyIP = Join(Split(@IPADDRESS0, ' '), '')

Top
#201529 - 2011-02-07 10:44 PM Re: Pull data from another kixtart script [Re: ShaneEP]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I went with the bad coding \:\) thanks for the help though.
_________________________
Where ever you go, there you are.

Top
#201530 - 2011-02-07 11:13 PM Re: Pull data from another kixtart script [Re: Tesdall]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Well just in case you change your mind, don't be intimidated by INI's. Kix makes it real easy to read and write from them. Here's a short simple example of how you could achieve what you're trying with an INI and 2 lines of code.
 Code:
$ip = Join(Split(SubStr(@IpAddress0,1,11)," "),"")
$Server = ReadProfileString(@ScriptDir+"\subnets.ini","SUBNETS",$ip)
? $server
get $
And the INI would be names subnets.ini and look like this...
 Code:
[SUBNETS]
10.111.1 = Server1
10.11.100 = Server2
192.168.1 = TestServer

Top
#201534 - 2011-02-08 02:53 PM Re: Pull data from another kixtart script [Re: ShaneEP]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
I am willing to try new things, as i was trying the code from Glenn. It was bombing out but as he said it was a quick script he just put together. I used the script you made and setup the ini file and worked instantly. I have to go edit a bunch of scripts now.... \:\(

Anyways, thanks for the help.
_________________________
Where ever you go, there you are.

Top
#201535 - 2011-02-08 04:28 PM Re: Pull data from another kixtart script [Re: Tesdall]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Shane's example will work, but will assume that all networks are /24. This is unrealistic in most situations. Using the IsInSubnet UDF will match on any CIDR address. A good example of this is if I change the record that represents my network subnet from 172.20.195.0 to 172.20.190.0, my server would change from ServerL to ServerA, because my IP address would be part of the larger network 172.16.0.0/16.

Here's a clean version of my example:
 Code:
Break Off

 call .\EnumINI.udf'
 call .\IsInSubnet.udf'

; This loads an array of W.X.Y.Z/mask network ranges
$aNetworks = EnumIni('.\subnets.ini', 'SUBNET_LOOKUP')			; load subnet table from common location
'There are ' UBound($aNetworks) + 1 ' records in the array' ?


; Get my IP address in normalized (no spaces) format
$MyIP = Join(Split(@IPADDRESS0, ' '), '')				; remove spaces
'My IP Address is ' $MyIP ?

; Pass IP and network table to UDF, returning an array of 0/1 values. 
; If the table is defined in most to least specific order, the first 
; value that is set represents the network subnet where the host resides
$aNetwork = IsInSubnet($MyIP, $aNetworks)                           ; get network ID (array element)


; find the first "1" in the array returned (may required additional args)
$Net = AScan($aNetwork, 1)                                          ; get first network that host is a member of


; Using the element returned above, get the value to read from the INI file
$Network = $aNetworks[$Net]                                         ; return the network/mask for lookup
$aNetworks[$Net] ?

; Read the server name from the central INI file
$Server = ReadProfileString('.\subnets.ini', 'SUBNET_LOOKUP', $Network) ; lookup the server name for this network

'My server: ' $Server ?
I added my local and regional networks to the ini as shown here:
 Code:
[SUBNET_LOOKUP]
10.11.1.0/24=Server1
10.11.2.0/24=Server2
10.0.0.0/8=Default_Server
172.20.195.0/24=ServerL
172.16.0.0/16=ServerA
Note that this assumes that the UDF files and the SUBNETS.INI file are in the current folder, which is reasonable for testing. When I run this script, I get the following output:
 Code:
There are 5 records in the array
My IP Address is 172.20.195.81
172.20.195.0/24
My server: ServerL
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#201583 - 2011-02-14 09:19 PM Re: Pull data from another kixtart script [Re: Glenn Barnas]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
All of our subnets are 24 at this point ... i think we have over 20.

Example:
10.20.1.0
10.200.1.0

So the way things are setup right now should work for a long time.

Thanks for the heads up that the script may not work in the future.
_________________________
Where ever you go, there you are.

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

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