Solved

Services file

Posted on 2003-11-12
22
2,775 Views
Last Modified: 2013-11-13
I administrate a Domain, I need a bat file to run at login that will add this entry into the
c:\winnt\system32\drivers\etc\services file
"sapmsP02   3600/tcp"
I have 300 workstations all NT workstation and need to automate this process.
0
Comment
Question by:bthorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 5
  • +1
22 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9735691
bthorn:

> I administrate a Domain, I need a bat file to run at login that will add this entry into the
> c:\winnt\system32\drivers\etc\services file
> "sapmsP02   3600/tcp"
> I have 300 workstations all NT workstation and need to automate this process.

You're probably better off providing the updated services file, instead of trying to alter the existing ones.  In your login script, you can do this:

copy \\SERVER\Share\Services.Txt %WINDIR%\system32\drivers\etc\services

Hope that helps,
Dex*
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 9747261
Probably this will help :

echo sapmsP02   3600/tcp >> c:\winnt\system32\drivers\etc\services

0
 
LVL 16

Expert Comment

by:_nn_
ID: 9748319
Usually, that file is only writeable for administrators, so i doubt a logon script will help (unless all your users are administrators, which is unlikely).

I'm not really a network admin, so I would just copy the new services file on \\station\admin$\system32\drivers\etc. Provided I have a list of the workstations, I would write a small batch parsing that list and deploying the new file. Though, I guess that 'real' admins have better tools, GPO(?), administration kits, you name it, in order to deploy new system files. Maybe you should ask in the OS-related Topic Areas (WinNT and/or Win2K) or in the networking ones (WinNT Network and/or Microsoft Networking)
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 19

Expert Comment

by:Dexstar
ID: 9749247
bthorn:

What _nn_ said about security is true.  This is going to have to be done from an admin account.  You could use a VBScript that will enumerate all the machines on your network, connect to the admin share, edit the text file, and then move on to the next one.

That's how I would do it.

Dex*
0
 

Author Comment

by:bthorn
ID: 9752668
tkalchev that worked fine in a script from my Domain Controller, the only remainig problem is that the line gets added to the end of the rest of the lines.  And in about the middle of these lines there is a statement saying "sapmstnt    3600/tcp" . so I need the new line before the old line or delete the old line out and add the new line.  Any idea?
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 9753393
echo sapmsP02   3600/tcp >> c:\winnt\system32\drivers\etc\services
type c:\winnt\system32\drivers\etc\services | find /v "sapmstnt    3600/tcp" > c:\winnt\system32\drivers\etc\services

The commands will add the line "sapmsP02   3600/tcp " to the end of the file and then will delete the old line "sapmstnt    3600/tcp".

Is this OK for you ?
0
 

Author Comment

by:bthorn
ID: 9754217
the type line deleted all entries in services file...I did use the quotes, was I supposed to?
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 9754318
Ok, maybe it is a problem of the format. Change the second command to :

type c:\winnt\system32\drivers\etc\services | find /v "3600/tcp" > c:\winnt\system32\drivers\etc\services

This should work 100%
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 9754330
Ops, sorry, line should be :

type c:\winnt\system32\drivers\etc\services | find /v "sapmstnt" > c:\winnt\system32\drivers\etc\services
0
 

Author Comment

by:bthorn
ID: 9754706
I've really got a problem here the echo command from tkalchev added the line but it was only tested on a workstation that did have admin rights. A generic user and the command that i put in the bat file to run at logon does not work.
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 9754720
Of course only the administartor can do this, normal users cannot edit anything under c:\winnt\system32
0
 

Author Comment

by:bthorn
ID: 9754731
I am the Domain Administrator and have rights to the local administrator group which includes Domain Admin which resides on all local pc"s.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9754754
Just as I told you. Dex* proposed a VBscript, I could propose you a batch you would have to run with admin rights :

@echo off
for /f "skip=3" %%a in ('net view') do call :do_it %%a
goto end

:do_it
net use %1
if ERRORLEVEL 1 goto end
if not exist %1\admin$\system32\drivers\etc\services goto disconnect
find /I "sapmsP02" %1\admin$\system32\drivers\etc\services
:: bypass if the target file already has the correct mapping
if "%ERRORLEVEL%" == "0" goto disconnect
:: overwrite with a locally prepared new file
copy /Y c:\somewhere\new_services.txt %1\admin$\system32\drivers\etc\services
:disconnect
net use %1 /del
:end
0
 

Author Comment

by:bthorn
ID: 9754893
_nn_  It looks like your telling me if I run this From the administrators account it will go out to my domain pc's and copy the new file. I need to know how I could test this on a small scale instead of globally also if I copy and paste your file into a bat file I would assume I need only change c:\somewhere\new_services.txt to \\SERVERNAME\SHARE\services
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9755128
>> I would assume I need only change c:\somewhere\new_services.txt to \\SERVERNAME\SHARE\services

Correct.

>> I need to know how I could test this on a small scale instead of globally

Create a small text file with 2~3 PC names like

\\PC1
\\PC2

and use

for /f %%a in (list.txt) do call :do_it %%a

instead of

for /f "skip=3" %%a in ('net view') do call :do_it %%a


On the other side, I believe you got a more elaborated script in that other question you posted in WinNT. I know that expert, you can trust him, he knows his "****" ;)
0
 

Author Comment

by:bthorn
ID: 9756830
nn this seems to work great one more test and were done
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9757312
You should use nn's batch file to do the work, and then use this utility to exec it on each PC without having to visit each one:
http://www.sysinternals.com/ntw2k/freeware/psexec.shtml

Dex*
0
 

Author Comment

by:bthorn
ID: 9760619
nn it works fine and touches all pc's including servers, so i need to only alter pc's so have decided to  substitute line with the text file entry. put the list.txt in the dir that i'm running script from and the dir that the services file is in. Cannot get it to work with the list. I substituted the line exactly how you indicated previously.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9760678
Hmmm,

- is the list file visible to the batch at the moment it needs it ?
- what is the format of the names inside ? "PC1" or "\\PC1" ?
0
 

Author Comment

by:bthorn
ID: 9760714
i made a test on my network domain at home, made a list.txt file with this format

\\joe
\\jim
\\jack

substituted the line you said to, then copied the file list.txt to the same directory where the script is being run from and also to the directory where the services file \\SERVERNAME\SHARE\services is at.
0
 
LVL 16

Accepted Solution

by:
_nn_ earned 500 total points
ID: 9760743
Hmm, setup looks fine... Can you please comment out the @echo off, run the script and paste its output here ?
0
 

Author Comment

by:bthorn
ID: 9760935
was my mistake the pc i checked had a problem all others worked i'm happy
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Part One of the two-part Q&A series with MalwareTech.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question