Bash script for remote command execution

March 21, 2013
bash programming

I’ve come across this a couple of times. As a system admin’s day to day tasks, your boss must have at some time given you a long list (let’s say 50+) of servers and all you got to do is getting some system information. Yeah, I know the feeling. It was the boring task when I started as a system admin until scripting twinkled in my mind.

See the below code, does it look familiar ?

#!/bin/bash
# remoteCmd.sh : The script that runs remote commands

for i in `cat $1`
do ssh $i "uname -a" 2>/dev/null
done

Save the content in a file as ‘remoteCmd.sh’. Put your server names in a file like ‘serverList’. Give your script execution right.

chmod +x remoteCmd.sh

You can now run the script as follows :

./remoteCmd.sh serverList

Functional Programming by Renghen

May 28, 2017
programming meetup mauritius-software-craftsmanship-community

braincheck() perl script

March 4, 2014
linux programming

Visual Studio 2013 virtual launch

November 19, 2013
windows programming user-groups-mauritius journal microsoft