Execute commands remotely on multiple nodes

Hello Team,

I have a requirement explained below.
I have 5 nodes/servers as follows.

Linux version:
Linux 3.10.0 (RHEL)

I am working on a Data Migration Project where I have to do the following once in every 10 steps for example in all the 5 nodes.
i. switch user to root.
sudo su -

ii. check the status of the service as follows (command)
service abc_pqr status

iii. start/stop service (commands)
service abc_pqr start
service abc_pqr stop

Once the service is turned off, the DB backup process will happen.
once the backup process is completed, the service will be turned ON.

Is there anyway I can remotely perform these steps?
I will do all these steps only in the node xyz1111 and from the same node I can do it remotely to the other nodes?
I can write a small script and I will place the script in all the nodes. Whenever I want I will trigger the script from the node xyz1111?

Note: Once I logged in to thse servers, I need to switch user to root. If I do manually, I will be prompted with Username and Password (So I need to store username and password in a file/hidden file). Because these commands will be executed only in root.

The manual process is taking time. I have given 5 nodes for example. In realtime, I will be having 10 nodes or more than that. Hence I am looking for some automation process to cut short the time.

Can anyone help us out to fix this issue?

Thanks in advance.

Hi Kmanivan,

Have you come across Ansible, it may seem like a sledgehammer to crack a nut, however it makes applying changes across a large group of hosts very straightforward and is a handy string to have in your administration bow.

Failing that, you could set up your user with passwordless sudo on each node and either copy over the script and make it executable or issue the commands through sudo (does anything require you to BE root when issuing these commands?) over ssh.

1 Like