Jassi
Jassi

Reputation: 541

How to connect to multiple servers to run the same query?

I have 4 servers where we have log files in same pattern. For every serch/query I need to login to all servers one by one and execute the command.

Is it possible to provide some command, so that it will login to all those servers one by one automatically and will fetch the output from each server?

What configuration, settings etc I have to do to make it working. I am new to Linux Domain.

Upvotes: 2

Views: 2863

Answers (3)

Vishal
Vishal

Reputation: 1209

Use https://sealion.com. You just have to execute one script and it will install the agent in your servers and start collecting output. It has a convenient web interface to see the output across all your servers.

Upvotes: -1

S.Spencer
S.Spencer

Reputation: 611

As suggested in your question comments, there are a number of tools to help you in performing a task on multiple machines. I will add to this list and suggest Ansible. It is designed to perform all of the interactions over ssh, in quite a simple manner, and with very little configuration.

https://github.com/ansible/ansible

If you were to have server-1 and server-2 defined in your ~/.ssh/config file, then the ansible configuration would be as simple as

[myservers]
server-1
server-2

Then to run a command on the group

$ ansible myservers -a uptime

Upvotes: 4

tripleee
tripleee

Reputation: 189427

If your servers are called eenie, meanie, minie, and moe, you simply do

for server in eenie meanie minie moe; do
    ssh "$server" grep 'intrusion attempt' /var/log/firewall.log
done

The grep command won't reveal from which server it is reporting a result; maybe replace it with ssh "$server" sed -n "/intrusion attempt/s/^/$server: /p" /var/log/firewall.log

Upvotes: 2

Related Questions