Wednesday, June 30, 2021

Executing scripts on remote servers with ShellScript

Create a file with list of servers. 
Here in this example, created file "list_of_servers.txt" file containing list of servers IP/Hostnames.

#!/bin/bash
cnt=1
for each_server in $(cat list_of_servers.txt)
do
	echo "$cnt. working on ${each_server}"
	scp file_to_copy.sh user@${each_server}:/tmp
	ssh user@${each_server} "sh /tmp/file_to_copy.sh"
done

***

No comments:

Post a Comment