#! /bin/bash
echo "########### connecting to server and run commands in sequence ###########"
ssh -i ~/.ssh/ec2_instance.pem ubuntu@ip_address 'touch a.txt; touch b.txt; sudo systemctl status tomcat.service'
#!/bin/bash
username="user"
servers=("srv-001" "srv-002" "srv-002" "srv-003");
script="pwd;"
for s in "${servers[@]}"; do
echo "sshing ${username}@${s} to run ${script}"
(ssh ${username}@${s} ${script})& # Run in background
done
wait # If removed, you can run some other script here