Computing.Net > Forums > Programming > Batch pull Variable from TXT or CSV

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch pull Variable from TXT or CSV

Reply to Message Icon

Name: strive
Date: January 4, 2008 at 13:40:32 Pacific
OS: Window XP
CPU/Ram: AMD Opteron/2GB
Product: self
Comment:

Hi everyone,
STRIVE here.

I am not a programmer. I hardly ever have to write my own scripts. Batch files is about the extent of what I do. I am a windows system admin.

I have a batch file to add shares to a cluster and I want to get it to use parameters and then pull the answers from a txt or csv file. Or I want input boxes to pop up for the answers.

Here is what I have.

cluster resource "MGMT1$" /create /group:"Group 00" /Type:"File Share"
cluster resource "MGMT1$" /priv Security=Everyone,set,R:security
cluster resource "MGMT1$" /priv Security=Administrators,set,F:security
cluster resource "MGMT1$" /adddep:"Disk V:"
cluster resource "MGMT1$" /priv ShareName=MGMT1$
cluster resource "MGMT1$" /priv Path="V:\MGMT1"
cluster resource "MGMT1$" /priv Remark=Fuji
cluster resource "MGMT1$" /on

This works like a champ, but I need to repeat it 50 times with different "Share Names, Disk, and Path"

The next one would look like this.
cluster resource "ATHMT1$" /create /group:"Group 00" /Type:"File Share"
cluster resource "ATHMT1$" /priv Security=Everyone,set,R:security
cluster resource "ATHMT1$" /priv Security=Administrators,set,F:security
cluster resource "ATHMT1$" /adddep:"Disk T:"
cluster resource "ATHMT1$" /priv ShareName=ATHMT1$
cluster resource "ATHMT1$" /priv Path="T:\ATHMT1"
cluster resource "ATHMT1$" /priv Remark=Fuji
cluster resource "ATHMT1$" /on

So, any help will be appreciated. Thanks,
STRIVE



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: January 4, 2008 at 19:33:43 Pacific
Reply:

Unless your shares stop following that predictable formula, all you really need is the path. Being an admin, I'm just going to assume you know what to do with %1.

FOR /F "delims=" %%a IN (%1) DO (
cluster resource "%%~Na$" /create /group:"Group 00" /Type:"File Share"
cluster resource "%%~Na$" /priv Security=Everyone,set,R:security
cluster resource "%%~Na$" /priv Security=Administrators,set,F:security
cluster resource "%%~Na$" /adddep:"Disk %%~Da"
cluster resource "%%~Na$" /priv ShareName=%%~Na$
cluster resource "%%~Na$" /priv Path="%%a"
cluster resource "%%~Na$" /priv Remark=Fuji
cluster resource "%%~Na$" /on)

For reference, your input file should look like:
V:\MGMT1
T:\ATHMT1
Win admins unite?

EDIT: Fixed, per klint's suggestion.


0

Response Number 2
Name: klint
Date: January 5, 2008 at 03:53:48 Pacific
Reply:

Razor, shouldn't that be FOR /F %%a IN (%1) ?

(I assume %1 is the name of a file containing lines that go into %%a.)


0

Response Number 3
Name: Razor2.3
Date: January 5, 2008 at 06:57:41 Pacific
Reply:

Yes, yes it should. Good eye there, klint.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch pull Variable from TXT or CSV

Batch Help! Pull data from .txt www.computing.net/answers/programming/batch-help-pull-data-from-txt/16173.html

Batch File|Input from txt file www.computing.net/answers/programming/batch-fileinput-from-txt-file-/17293.html

getting a variable from batch file www.computing.net/answers/programming/getting-a-variable-from-batch-file/16771.html