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

Batch pull Variable from TXT or CSV

Reply to Message Icon

Original Message
Name: strive
Date: January 4, 2008 at 13:40:32 Pacific
Subject: Batch pull Variable from TXT or CSV
OS: Window XP
CPU/Ram: AMD Opteron/2GB
Model/Manufacturer: 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


Report Offensive Message For Removal

Response Number 1
Name: Razor2.3
Date: January 4, 2008 at 19:33:43 Pacific
Subject: Batch pull Variable from TXT or CSV
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 2
Name: klint
Date: January 5, 2008 at 03:53:48 Pacific
Subject: Batch pull Variable from TXT or CSV
Reply: (edit)

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.)


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: January 5, 2008 at 06:57:41 Pacific
Subject: Batch pull Variable from TXT or CSV
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch pull Variable from TXT or CSV

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software