Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use an array to excuting command

Status
Not open for further replies.
Jul 30, 2004
7
US
Hi Everyone,

I need help with the array execution portion of this script, I left the different options I've tried so far commented. The line that has not been commented works but does not help me with my final goal. I would like to, if possible read the server names from the text file then execute the command below on every one of those servers listed in the text file.

Can someone please help me solve this, not even sure if what I'm trying to do is possible? I’m not a programmer so if what I’ve strung together is wrong please let me know.

Kind Regards

Herschel

-----------------------------------------------------------

Const ForReading = 1
Const SERVERS = "C:\servers-list.txt" 'this file contains the name of the server that I want to run the command below on

Dim fso, f
Dim arrText()
Dim iUpperBound
Dim SourcePath,SourceFile,DestPath, String


Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso_OpenTextFile(SERVERS, ForReading)

iUpperBound = 0
While Not f.AtEndOfStream
ReDim Preserve arrText(iUpperBound)
arrText(UBound(arrText)) = f.ReadLine
iUpperBound = iUpperBound + 1
Wend

f.Close

For Each elem In arrText
'shell.run "C:\program" &"\\" & elem &" -i -w C:\TestFolder\admutils\stat -tT -fmyserver -aAdministrator -ppassword -S-30 -o\\fileserver\c$\servername_monthly_stat.csv -l6 -h" 'if possible when creating the [servername_from_list].csv file I would like to use the server name read from the server.txt file
shell.run "C:\program \\TheServer -i -w C:\TestFolder\admutils\stat -tT -fmyserver -aAdministrator -ppassword -S-30 -o\\fileserver\c$\servername_monthly_stat.csv -l6 -h"
 
Hello spikeman24,

Problem is to clarify which program located at which computer and exceuted where with parameter from where.

[1a] c:\program stands for the executable I suppose, ie something like c:\notepad.exe to take a simple example.
[1b] c: is the drive on computer where the script is running?
[1c] If 1a is affirmative, you want to execute "program" on the local computer where the script is running?
[2] \\TheServer: TheServer is the string literal of elem? which is a remote computer?
... the questions continue but turn utterly stupid in appearance. So maybe you clarify all the element in the command along the line of the reasoning above.

regards - tsuji
 
I apologise for not being clear in my first post, I was even confusing myself when I read the post again this morning. So let me try again hopefully I can do a better job this time round.

The script runs locally, and the program it’s going to run is also local. However the program I want to execute (beyondexec.exe) together with its parameters runs a command on a remote servers. The name of the remote servers is contained in the servers.txt file. As an example using notepad.exe, if I was to run the command on one server by statically specifying the command line it will look like this:

Example 1

beyondexec \\server1 c:\windows\notepad.exe

Now want I want achieve by using a script and array is to run the same command as specified in example 1 on all the servers listed in the servers.txt. I’m likely to add or remove servers from the list.

server.txt file contents:
-------------------------------------------------
server1
server2
server3
server4
-------------------------------------------------
 
spikeman24,

I'm not sure I understand it entirely. But try this see what gives.
[tt]
[green]For Each elem In arrText
shell.run "C:\program \\[red]" & elem & "[/red] -i -w C:\TestFolder\admutils\stat -tT -fmyserver -aAdministrator -ppassword -S-30 -o\\fileserver\c$\servername_monthly_stat.csv -l6 -h"

'suppose there is a next down there[/green]
[/tt]
I suppose in the arrText, the elements are ("server1",...)

- tsuji
 
Thanks tsuji,

Can you believe I was missing the second "&" after the elem.

Thanks Once again,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top