Perform set of actions only on servers identified in the script

Hey EE!  As I near the end of this script file project, I needed to ask how I can apply the actions listed in my batch script to only a few servers.  I broke the script into three parts; creating a log file (if one didn't exist and renaming it if it did exist), next, moving the files from the production directory out and copying the new ones in.  Lastly, the meat of the script.  The services are stopped, files from the prod directory are copied to the server's local directory and services started back up.  Each action has a echo command to dump the results.

What I would like to do is list the servers that the last steps needs to apply to, then run the script and it would loop through for each server and when all servers have been touched, the script would end.

I am not a very skilled coding guy so please keep that in mind when you post your suggestions.  I may need more info than a simple "do this" or "try that".  Thank you in advance!!  (If you need to see some of the script, let me know but it's just a batch file).
LVL 9
samiam41Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
How many servers are you talking about, 5 to 10, or many dozens?

~bp
samiam41Author Commented:
3 or 4
Bill PrewIT / Software Engineering ConsultantCommented:
In that case you could just have the list of servers specified in the script, and loop through them, doing all the other logic you already have for each server.  You might use your existing code as an external BAT file that you CALL passing it the server name as a parm, or you could put it all in the same script as a subroutine, or inside the FOR loop shown below.

set ServerList=server1,server2,server3,server4

for %%A in (%ServerList%) do (
  echo Processing server: %%A
  REM do any of your logic here referencing this server
)

Open in new window

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

samiam41Author Commented:
Brilliant work BP.  Thank you.  Testing now.
samiam41Author Commented:
BP, here is a portion of the code that I need to have ran on each of the four servers.  I'm not sure how to plug this into the code you posted previously.

echo ################### >> "%logfile%"

:service_stop
net stop "gateway service" && (
	ECHO NFS Service was stopped at %time% >>"%logfile%
) || (
	ECHO NFS Service encountered error level %errorlevel% 'at' %time% when trying to stop the service >>"%logfile%
)

echo ################### >> "%logfile%"

:overwrite_existing_local_group_passwd_files
if exist c:\SFU\mapper\group (
	echo Overwrote existing group file >>%logfile%"
	xcopy \\server\nfs\new\group c:\sfu\mapper\ /Y
) else (
	echo *Critical Error* code %errorlevel%. Group file was not copied to local directory at %time%. >>%logfile%	
	goto :end 
)

if exist c:\SFU\mapper\passwd (
	echo Overwrote existing passwd file >>%logfile%"
	xcopy \\server\nfs\new\passwd c:\sfu\mapper\ /Y
) else (
	echo *Critical Error* code %errorlevel%. Passwd file was not copied to local directory at %time%. >>%logfile%	
	goto :end 
)

Open in new window


Essentially I am stopping the NFS service on the local server, copy over a file and then starting the NFS service.  Thoughts?
samiam41Author Commented:
Unless you mean to have each step be coded to run on the servers before moving to the next step...  Testing that out.
Bill PrewIT / Software Engineering ConsultantCommented:
You will need to adapt you code to specify the server to perform the action on, since I believe what you are after is the ability to run a single script from an administrator type computer, and have that script reach out to each of the remote computers and perform the required actions?

If so, then you will need to specify a server name in any of the commands that allow it, and if you are referencing things like the C: drive you will need to refer to that using a sharename, like:

\\computername\c$

for the NET STOP commands, you will need to replace those with the SC command, which can do the same type of things (and more) but has the capability to take a server name as a parameter, and perform the action on a remote server.

Does that help?

~bp
samiam41Author Commented:
Sure does.  Testing with the improvements.
samiam41Author Commented:
A new, critical issue has arisen and my time on this side project has come to a close for now.  I appreciate your help and time with these series of questions.  Take care BP!
Bill PrewIT / Software Engineering ConsultantCommented:
Welcome, glad I was able to help some, thanks for the feedback.

~bp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.