0

I'm having some hard time finding examples of something relatively simple: At my job, I need to come up with a script to test various servers with curl and then get the outputs in a file.

The command to use is something along $ time curl https://something.net

I need to run this command in multiple hosts, so here's how the process would look like :

1 - run script from local workstation

2 - script ssh to host 1 and runs curl ---> record the output

3 - script ssh to host 2 and runs curl ---> record the output

4 - etc …

5 - script retrieves all the outputs and writes them to a file in my local host.

What would be the easiest technology to use? examples are welcome.

Notauser
  • 295
  • 1
  • 9

1 Answers1

1

What about something like that?

#!/bin/bash
url=http://something.net/
hosts=(host1 host2 host3)

for host in "${hosts[@]}"; do
  echo $host
  ssh "$host" -- time curl "$url"
  echo
done

still needs to be redirected to a file, but simply iterates over the list of servers and invokes the command there.

Andreas Rogge
  • 2,853
  • 11
  • 24
  • Exactly what I was looking for, many thanks. I'll accept the answer once tested – Notauser May 02 '19 at 18:39
  • 1
    I ended up modifying the script to capture and append to a txt file like this ```#!/bin/bash url=http://something.net/ hosts=(host1 host2 host3) for host in "${hosts[@]}"; do echo $host >> somefile.txt ssh "$host" -- time curl "$url" 2>> somefile.txt done``` – Notauser May 03 '19 at 14:38