Tags

,

Sample shell script to login and execute commands in remote servers

Sample 1

#!/bin/bash

 for i in `cat servers.txt|awk {‘print $1’}`; do ssh $i “id;w”; done;

 

Sample 2

#!/bin/bash
for i in {10..30}
do
echo “in 192.168.10.$i”
ssh 10.93.228.$i ‘hostname;cd /etc/yum.repos.d/;cat HDP-UTILS.repo’
scp /etc/yum.repos.d/HDP.repo 192.168.10.$i:/etc/yum.repos.d/
echo -e “\n\n”
done

Advertisements