#120472 - 2004-06-02 11:20 AM
Variable Value call from another variable
|
Cypher
Fresh Scripter
Registered: 2004-06-02
Posts: 6
|
Hi,
I am just getting my head around this so sorry if my code is a bit bloaty (I'm sure there is a more streemed line way of doing it). My Problem is I would like to retrieve the VALUE of $Variable2 (ie MyServer1 ) by using $MyVar
$PubApp = "TestApp" $ServerCount = "2" $Variable2 = "MyServer1" $Variable3 = "MyServer2"
$Count = "1" ? "Start Loop To Remove Servers" while $count <= $ServerCount ; I could have used UNTIL here instead
$MyVar = "$Variable2" + $Count ; This should pull back the VALUE of $Variable2( ie MyServer1 ) ? $MyVar ; This ACTUALLY Pulls back - $Variable2 shell "cmd /c Setprop $PubApp /ds $MyVar $Count = $Count +1 Loop
I have tried changing the String Expressions and even used CHR(34) but it always seem to pull back the String Name and NOT the String VALUE. The Shell cmd it is eventually going to be running removes Citrix servers from Published applications WITHOUT using the CMC, but for this example it doesn't matter what is happening in the loop, it isn't pulling in the value of another variable. The only other way I can think of is possibly an Array or a FUNCTION, but thought I would ask the experts if there is a way of getting the Value of my first Variable, as it would be useful to know in the future.
Thanx guys T
|
|
Top
|
|
|
|
#120473 - 2004-06-02 11:55 AM
Re: Variable Value call from another variable
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I think I know what you are trying to do, but have you tried arrays
$servers='server1','server2','server3'
for each $server om $servers ? $server next
for $loop = 0 to ubound($servers)-1 ? $servers[$loop] next
it looks like you are trying to do $=execute('$$myvar = "server"+$count')
|
|
Top
|
|
|
|
#120474 - 2004-06-02 12:28 PM
Re: Variable Value call from another variable
|
Cypher
Fresh Scripter
Registered: 2004-06-02
Posts: 6
|
Yes, I did look at using an Array, I just need a way of populating the array automatcially, which I haven't worked on yet, whereas populating a variable was easy (ReadProfilestring) from a file called ServerList.ini
The end result is as thus
Each Published Application has live and contingent servers allocated to it. Because there are multiple servers for each published application there is in built redundency, but should the worst happen, the DR Servers would need to replace the existing servers. For this to happen Each Published Application has a ServerList.ini File with the following Sections
[RemoveServers] Server1 = UK0034 Server2 = UK0098 Server3 = "" Server4 = "" etc up to Server10
[AddServers] Server1 = DR_SC0022 Server2 = DR_SC9625 Server3 = "" Server4 = "" etc up to Server10
I was reading in these lines into my Variable, can a bulk read happen to populate the the array ???
Cheers for the assistance T
|
|
Top
|
|
|
|
#120475 - 2004-06-02 01:56 PM
Re: Variable Value call from another variable
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
|
Top
|
|
|
|
#120476 - 2004-06-02 01:56 PM
Re: Variable Value call from another variable
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You can read the file into an array, but I suspect that you can do what you want more easily using something like the following, assuming a "serverlist.ini" file in the same directory:
Code:
$sINIFile=".\ServerList.ini"
For Each $sKey In Split(ReadProfileString($sINIFile,"RemoveServers",""),Chr(10))
If $sKey
$sServer=ReadProfileString($sINIFile,"RemoveServers",$sKey)
"Server to remove is : "+$sServer+@CRLF
EndIf
Next
For Each $sKey In Split(ReadProfileString($sINIFile,"AddServers",""),Chr(10))
If $sKey
$sServer=ReadProfileString($sINIFile,"AddServers",$sKey)
"Server to add is : "+$sServer+@CRLF
EndIf
Next
Using your sample file I got:
Quote:
Server to remove is : UK0034
Server to remove is : UK0098
Server to add is : DR_SC0022
Server to add is : DR_SC9625
|
|
Top
|
|
|
|
#120477 - 2004-06-02 02:23 PM
Re: Variable Value call from another variable
|
Cypher
Fresh Scripter
Registered: 2004-06-02
Posts: 6
|
Richard,
Thanx for that, it looks good, although I assume you referenced the $ServerCount in there somewhere as I cannot see where it knows when to stop when it arrives at a blank entry (ie Server3 = )
Cheers Tony
|
|
Top
|
|
|
|
#120478 - 2004-06-02 02:57 PM
Re: Variable Value call from another variable
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
No, the benefit of the technique I used is that it will enumerate the entries in an INI section, whether there is 1 entry or 101 entries. You don't need to determine the size before-hand.
This means that your INI file will only have entries which have values, it doesn't need VALUE99="" as a place-holder.
If you *must* have entries with null values then you just need an extra check in the loop(s) to avoid processing them.
For example:
Code:
For Each $sKey In Split(ReadProfileString($sINIFile,"RemoveServers",""),Chr(10))
If $sKey
$sServer=ReadProfileString($sINIFile,"RemoveServers",$sKey)
If $sServer "Server to remove is : "+$sServer+@CRLF EndIf ; ** NEW CONDIFIONAL HERE **
EndIf
Next
|
|
Top
|
|
|
|
#120479 - 2004-06-02 03:24 PM
Re: Variable Value call from another variable
|
Cypher
Fresh Scripter
Registered: 2004-06-02
Posts: 6
|
Richard,
I understand now, your INI file only had the entries in that were required. I have added in a "nul" value so it should now stop when it reaches the first blank entry and ends the loop. Unfortunately as all the INI files are based on a Template some may have Blank entries in them, so I cannot go through them all and edit them.
Thanx to all for your assistance, In closing the only way around this I found was to use an ARRAY
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|