Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using a variable in a BASH command?

Tags:

linux

bash

ubuntu

I have 20 machines, each running a process. The machines are named:

["machine1", "machine2", ...., "machine20"]

To inspect how the process is doing on machine1, I issue the following command from a remote machine:

ssh machine1 cat log.txt

For machine2, I issue the following command:

ssh machine2 cat log.txt

Similarly, for machine20, I issue the following command:

ssh machine20 cat log.txt

Is there a bash command that will allow me to view the output from all machines using one command?

like image 467
user3262424 Avatar asked Jul 18 '26 00:07

user3262424


1 Answers

If the machines are nicely numbered like in your example:

for i in {1..20} ; do ssh machine$i cat log.txt; done

If you have the list of machines in a file, you can use:

cat machinesList.txt | xargs -i ssh {} cat log.txt
like image 119
chrisaycock Avatar answered Jul 20 '26 16:07

chrisaycock