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
- Create a serverlist.txt file with a line by line list of servers.
- 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
- chmod 755 script-filename
- ./script-filename