Link to home
Start Free TrialLog in
Avatar of Batuhan Cetin
Batuhan CetinFlag for Türkiye

asked on

Extract strings from multiple text files

Hi,

I have an application that works based on an "optionfile.app" on each server. This is actually a txt file that can be opened with notepad. The path of the optionfile is the same in all servers, something like "C:\App\optionfile.app".

I need a script to pull two specific lines from every optionfile.app from every server. Assume that the optionfile is something like this:

Communication   tcpip
Port   1500
TCPaddress    10.0.0.4
ServerName     server1
Passwordaccess     password

From every optionfile, I need to extract these two lines:

TCPaddress    10.0.0.4
ServerName     server1

and output to a txt or csv file, does not matter. I've done some research that I can extract this with VB.net and using RegEx but this will run on every server (Windows 2003, 2008 both x86 and x64) so I don't think a .NET solution is reliable.

Any help and direction appreciated. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Batuhan Cetin

ASKER

Thanks kaufmed, this is working exactly as I want on a single server. I need to pull this info from many servers, so I need to modify "inFilename" parameter to meet the following;

1) Because I will get this info from multiple servers, the path must be smething like;

inFilename = "\\" & serverlist & "\c$\App\optionfile.app"

and serverlist will be a txt file that includes server names each per line. VBS must connect to each machine from that list at a time.

2) Also on some servers the name of the optionfile.app file is modified like "optionfileV1.app" or "old_optionfile.app". These are renamed by server admins so I can't tell exactly. So I will need to search for;

*optionfile*.app

How can I do this? Thanks.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow, thanks that's wonderful. I don't know a lot about batch scripting so I didn't understand much of the code but it works :)

However I will wait for kaufmed if he can show me a way to do it with VBS, then split the points. Thanks again.
Oh billprew, I was messing around with your script and I realized the script hangs (most probably retrying in background) when it can't reach a server. How can I get past this? I need it to continue to the following server if it can't reach the current server. The reasons might be the server is shutdown, the service account does not have permission to access "C$" on that machine, cannot resolve DNS name, etc..

Can we set something like a timeout? Each *.app file takes at most 10-15 sec to be processed. Can we tell the script to continue to next server if it can't get the app file in that time? Preferebly write an error message ("Access Failed") to the output file?
After I wrote my last comment, I see that the script actually moved on to the next server, after waiting about 5-10 minutes.

This is good news but if possible a timeout like 10 sec and an error message would be useful.
I'm sending multiple comments but the problem appears to be something totally different from a timeout issue.

In my first run against the server list, it get the info from the first server in the list, waited for 10 minutes, then jumped to the 428nd server in the list, continued and finished successfully from there on.

In my second run, after getting the info from 1st server, it jumped to the 3rd server, then some server else.

It seems to skip servers randomly. There are servers that the script got the lines at the first run, but not the second and vice versa.

I also tried to run the script against a single server which seems to be failed in both bulk runs and it worked!

Do you have any idea of this random jumps?
Avatar of Bill Prew
Bill Prew

Probably the next step would be to add a test as a server is read from the text file to try and make sure it's a valid server, is online, and that the share exists.  We can add some code to use PING etc to do some basic checking on the server being up.

~bp
>>  However I will wait for kaufmed if he can show me a way to do it with VBS

My post was VBS  :)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.