Link to home
Start Free TrialLog in
Avatar of T-Dev
T-DevFlag for United States of America

asked on

DOS: exec a command on every server in a file; problems with %% variables in DOS....

Hello. My ultimate goal is to schedule a defrag across all 134 servers by doing something like --> for /f %%servername in (c:\serverlist.txt) do schtasks /create /s %%servername..... and so on, BUT I'M HAVING DIFFICULTY with something very basic. For example, before I can present this script/batch file to management to convince them that it's safe, I'd like to do something very baby-ish with this script like just verify that it's reading my file, c:\testservers.txt correctly. Therefore, the first thing I did was create a .vbs file named "justnames.vbs" that looked like this (I'll show you the command to display it also):

C:\pscripts>type justnames.vbs
for /f %%svr in (testservers.txt) do echo %%svr

but when I run it by typing -->cscript justnames.vbs , it gives me this error:

C:\pscripts>cscript justnames.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\pscripts\justnames.vbs(1, 5) Microsoft VBScript compilation error: Expected identifier

OK; so, I'm thinking "well maybe the problem is that this isn't vbscript at all. Perhaps, this is just a plain DOS batch file, and should end in .cmd or .bat. So, I try both. I change the name of justnames.vbs to justnames.cmd and execute it, and this is what I get (with the renaming):

C:\pscripts>rename justnames.vbs justnames.cmd

C:\pscripts>dir
 Volume in drive C has no label.
 Volume Serial Number is 1075-4688

 Directory of C:\pscripts

01/31/2008  12:04 PM    <DIR>          .
01/31/2008  12:04 PM    <DIR>          ..
01/30/2008  03:15 PM                94 displaystatusofschtasks.vbs
01/30/2008  03:06 PM               131 displaystatusofschtasks.vbs.bak
01/31/2008  11:58 AM                49 justnames.cmd
01/30/2008  02:33 PM                70 testservers.txt
               4 File(s)            344 bytes
               2 Dir(s)     799,408,128 bytes free

C:\pscripts>justnames
%svr was unexpected at this time.

C:\pscripts>for /f %svr in (testservers.txt) do echo %svr

C:\pscripts>

SO, as you can see, it says that %svr was unexpected at this time. What is the problem here? The same thing happens when I name it justnames.bat. I tried using just one percent sign; that didn't make it work. Thanks 4 ur help.
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

That's a batch file not a vbs file. Name the file .bat or .cmd and try it.
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
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 T-Dev

ASKER

Hello SteveGTR,
    Thanks for answering my question. Looking at your code, the only difference I see is @echo off and setlocal... I added those things, but it still doesn't work. You said that my 'for' statement was formatted incorrectly.... Formatted? As in the colors? I can't really change that.... Other than that, I don't see any difference. Then again, there's my use of the variable %%svr instead of what you used, %%a.... Is that the problem? I should just test that........... Ok, here goes.......... (testing)........... whooooooop!!! It works! I don't get it. DOS didn't like my variable name? Evidently not. Anyway, I see that what I need to do is google DOS variable naming conventions, and I'll be properly on my way! You got it! Thanks!!

C:\pscripts>type justnames.bat
@echo off
 
setlocal
 
for /f %%svr in (testservers.txt) do echo %%svr
 
C:\pscripts>justnames
%svr was unexpected at this time.
C:\pscripts>

Open in new window

Avatar of T-Dev

ASKER

I had to hunt around to see just how my 'for' command was formatted improperly, but thanks to SteveGTR, I found it!!!!
You didn't look close enough. See that I changed: %%srv to %%a.
Also, here's a helpful hint... Never grade with anything other than an A. Doesn't cost you anything and doesn't cause bad blood. Do you understand how EE misguidedly assigns points to experts?

Got some bad blood here...
Avatar of Steve Knight
And of course there is no way of seeing now is there Steve... I wonder if grades are on the eay out.  they don't show on the question, or in the profile, and the last ten grades given either. They always have been a bit pointless and contention from the first Q I answered here many years ago.
I was hoping the same thing and said so when I reported this bad grade:

https://www.experts-exchange.com/questions/23127761/06-Feb-Another-Bad-Grade.html
It would appear that you can see what grades you have given and what grades you have received in your OWN profile but you can't see in someone else's profile what they have given.  Not good for the blacklist  Theres a bit about it in today's "ee community newsletter" mailing.  I suppose I better go on an tick the boxes for "Neglected question alerts".

Frankly it should be ebay-style, get a rating unrelated to the points, positive, neutral or negative with comments and the expert has the oppurtunity to do the same for the asker...
Anyway somewhat OT, I was just looking through alerts I had missed from today and couldn't help poking nose in!
Oh yeah being as this will be seen by whatever mods look at the link you posted.  what REALLY p&*&*s me off is that you can get an alert, answer the question with a link in the url that says MSDOS area say and appears in the MSDOS area and you get the points in "Miscellaenous applications area" or whatever because that is what the system suggested when the Q was posted.  Great, waste of time on the only thing keeping us here, competastion to get to next level of points etc, not to get 2000 points in a random zone.  Pahh!
Avatar of T-Dev

ASKER

I don't understand how EE gives points. As far as I can see, you got 100%, which seems to me reason you should be happy. Besides, I'm really happy I got the answer and I was happy that you, the EE star of DOS programming, was able to get to it. Why soil this with that attitude? The B was simply because I didn't know immediately what "formatted incorrectly" meant, and as you can see in my post, I eventually figured it out, and gave you credit for pointing me in the right direction! You must admit that "formatted incorrectly" could mean things like color or font, which, to you can't possibly make sense, but when you consider that this is my 5th question ever on EE, I don't know what to expect; everything is still so new! Peace out.
That is part of the problem. Ignorance of the way it works in regard to point distribution.

In my opinion a user assigns points and the expert should get rewarded with the points.

But, EE has a structure where the user grades the answer and the grade is used as a multiplier for the points. A times 4, B times 3, C times 2.

So in this case your 100 points converted to 300 points for me instead of 400 is you had graded as an A.

This policy is ridiculous in my opinion.

Add to this that up until a couple of weeks ago EE showed your last 10 grades on your profile. They recently did away with this because experts would not answer questions for people who had a history of bad grading. Now they don't show the history, further deemphasizing the need for grades.

You are on the other side of this, not an expert. You also are new to the site. So maybe you can't understand this.
Avatar of Netminder
Netminder

A request has been made to change the grade on this question, as the solution is concise, clear, and to the point.

If there are no objections in two days, the request will be granted.

Netminder
Site Admin
Avatar of T-Dev

ASKER

I object. He said my error was a result of incorrect formatting, and that can mean a lot more than the length of variables (it can mean spacing, capitalization, punctuation, font, color, etc); hence, it was ambiguous. Nevertheless, I admit that it led me in the right direction. Hence, a B is a great grade. For such accurate grading and being harrassed by this complaining, I should get expert points or a refund on the money I paid. Seems to me he's trying to manipulate people to always give As by threatening "bad blood". By caving into the pressure to always give As, it encourages the experts to slack off and not even proofread their solutions.
I gave you the corrected answer and pointed you to a reference to the for command help.

If you didn't understand then you should ask a question. I answered your question with 100% accuracy. I can't help that you don't read my comments.

Anyways you do what you want. I'm sick of dealing with you...

You're the first person on my new list of people I don't help. Congrats :)
Avatar of T-Dev

ASKER

You said: "I gave you the corrected answer and pointed you to a reference to the for command help." You're referring to--> "for /?", YOU ARE CORRECT that the answer is in there. However, I HAD TO GO LOOKING FOR IT. The B is a really great grade that acknowledges that benefit. You choose to be negative about it and not humble enough to see the imperfection in your own response.

Then you say that I should ask questions if I don't understand. Are you telling me that I should ask and THEN WAIT for an answer INSTEAD of pursuing the answer myself?? Why do you think I'm on EE? If you're going to be so negative over a B, then you're right; we're probably better off not working with each other.