First you can create a script that searches the two Jvms of the same server:
#!/bin/bash
cd
for dir in log_vm_1 log_vm_2
do
echo "procurando em" $(hostname) $dir
find $dir -type f -exec grep -l COD_ERRO_JVM {} \;
done
Notice that you don’t have to cd dir
and then find
, it is possible to pass the directory directly to the find
. By the way, if you know the complete path of the directory, not even the cd
at first it is necessary, you could just do find /caminho/completo/log_vm
.
In fact, if you want, you can pass several directories at once: find log_vm_1 log_vm_2
, so I wouldn’t need the for
. I made the for
up just to have a echo
between one directory and another, so that the respective outputs are visually more separate.
Assuming the above script is saved to the file busca.sh
(in some folder of your internal server), just connect to each of the client’s servers passing the name of the script as parameter:
ssh servidor_interno
for serv in servidor_cliente_1 servidor_cliente_2 servidor_cliente_3
do
ssh $serv "bash -s" < /pasta/do/arquivo/busca.sh
done
"bash -s" < arquivo
causes the commands to be read from the file. Then, they are executed on the client server, without the script needing to be there.
With this the commands of the script busca.sh
run on each of the client’s servers. The line with echo
prints the hostname
and the directory, so you will have an output similar to that:
procurando em servidor_cliente_1 log_vm_1
... saída do find
procurando em servidor_cliente_1 log_vm_2
... saída do find
procurando em servidor_cliente_2 log_vm_1
... saída do find
procurando em servidor_cliente_2 log_vm_2
... saída do find
... e assim por diante
Of course you can save the for serv ...
above in another script, if you like. For example, if I save in /pasta/busca_todos.sh
(on the internal server) and give permission to execute (chmod u+x busca_todos.sh
), I can run it directly by SSH:
ssh servidor_interno /pasta/busca_todos.sh
Thus, when logging into the internal server, the script busca_todos.sh
is executed. And within it there is the for
that makes a loop by all the client’s servers, running the search on each of them.
Another alternative is to copy the script busca.sh
for each of the client’s servers:
scp busca.sh servidor_cliente_1:/pasta
scp busca.sh servidor_cliente_2:/pasta
... copiar para todos os servidores do cliente
Since there is now a copy of the file on each client server, just pass the full path of it while doing SSH:
ssh servidor_interno
for serv in servidor_cliente_1 servidor_cliente_2 servidor_cliente_3
do
ssh $serv /pasta/busca.sh
done
Remembering that the script must have execution permission (it is necessary to execute chmod u+x busca.sh
on each client server so that it can be run).
hkotsubo, Thank you very much. It worked.
– Rodrigo Santos
@Rodrigosantos If the answer solved your problem, you can accept it, see here how and why to do it. It is not mandatory, but it is a good practice of the site, to indicate to future visitors that it solved the problem. And when I get 15 points, you can also vote in all the answers you found useful.
– hkotsubo