November 18

Linux: Bash Script to ssh to multiple servers run a command and the seprately print the output for each server

Prerequisite: must have ssh key authentication configured

  1. Create a serverlist.txt file with a line by line list of servers.
  2. Create a shell file with the following code(eg. servicechecker.sh:

!/bin/bash

for host in $(cat serverlist.txt); do ssh “$host” “systemctl status isecespd” >”output.$host”; done

  1. chmod 755 script-filename
  2. ./script-filename


Copyright 2021. All rights reserved.

Posted November 18, 2021 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B