Remote server's output

Hi All,

Can anybody help me, i have 50 servers within a network.
For checking the HDD utilization using df -k, Right now i am logging into each server daily and then noting the output.

I want that i should be able to run the command in all servers while sitting in single server and getting the output in a text file present at the server from where i am executing the script.

How can i do so?

for server in server01 server02 ... server50
do
  ssh "$server" "df -k"
done > "$textfile"

Or, if the server names are one to a line in a file:

while IFS= read -r server
do
  ssh "$server" "df -k"
done < "$file"  > "$textfile"
1 Like