Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

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).
Avatar of Bill Prew
Bill Prew

How many servers are you talking about, 5 to 10, or many dozens?

~bp
Avatar of samiam41

ASKER

3 or 4
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

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
Brilliant work BP.  Thank you.  Testing now.
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?
Unless you mean to have each step be coded to run on the servers before moving to the next step...  Testing that out.
SOLUTION
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
Sure does.  Testing with the improvements.
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!
Welcome, glad I was able to help some, thanks for the feedback.

~bp