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?
 
Bill PrewCommented:
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
0
 
Bill PrewCommented:
How many servers are you talking about, 5 to 10, or many dozens?

~bp
0
 
samiam41Author Commented:
3 or 4
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
samiam41Author Commented:
Brilliant work BP.  Thank you.  Testing now.
0
 
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?
0
 
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.
0
 
Bill PrewCommented:
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
0
 
samiam41Author Commented:
Sure does.  Testing with the improvements.
0
 
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!
0
 
Bill PrewCommented:
Welcome, glad I was able to help some, thanks for the feedback.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.