Create scripts that run in different servers
I have three servers that are used to manage a bunch of other client servers. One of the managing servers has nagios, the other h开发者_开发问答as a web proxy, another has an ldap and MySQL server.
Whenever I need to include a new client server, I have to log into Server A, and create the SQL entry, go to nagios and create the entry, go to the web server and add the proxy. You get the picture. What I would like is to be able have all servers share a scripts directory, say '/opt/boxes/scripts` and in there have a bunch of scripts that know where they can run. Say I'm in server A and run script X, that should run on server B, it will actually run in server B.
Is there a simple way to do this? Preferably perl bases since that is something i know a little bit about.
One easy way may be to make a directory for each script on each of the machines.
In one directory, the actual script runs. In all the other directories, the script does a ssh to the appropriate server and runs the actual script.
E.g.
Script to add client ssh servera -c servera-addclient-to-sql ssh serverb -c serverb-addclient-to-nagios ssh serverc -c serverc-addclient-to-webproxy
Adding scripts that know where they run is fairly easy too.
In loose form
$RunWhere = "XXXX"
$ScriptName = "YYYY"
if `hostname` ne "XXXX" {ssh $RunWhere -c $Scriptname @ARGS ; exit; }
else {
Do the actual stuff
}
So run from anywhere, it runs locally if thats the right thing to do, otherwise does a secure shell to the right place and runs the same command there.
精彩评论