Hadoop Cluster : Run Command on ALL Nodes

Its usually tough to run a command on all nodes of a hadoop cluster.

Here is a script to do that..

run_command

!/bin/bash

TPUT=’tput -T xterm-color’
txtund=$(${TPUT} sgr 0 1) # Underline
txtbld=$(${TPUT} bold) # Bold
txtrst=$(${TPUT} sgr0) # Reset
if [ $# -ne 1 ]; then
echo “Please pass the command to run as the first argument. Use single quotes if the command takes multiple arguments itself”
else
for host in `cat Hostdetail.txt`; do
echo -e “${txtbld}\n######################################################”
echo -e “# Running command $1 on Host: $host”
echo “######################################################${txtrst}”
ssh root@$host COMMAND=”‘$1′” ‘bash -s’ << ‘END’
$COMMAND
END
done
fi

Hostdetails.txt

server1

server2..

Usage:-

Eg:-

./run_command “ls /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/jre/bin/”

Edit Hostdetail.txt
** Dont include the node from which the command is being executed

Advertisements

About shalishvj : My Experience with BigData

6+ years of experience using Bigdata technologies in Architect, Developer and Administrator roles for various clients. • Experience using Hortonworks, Cloudera, AWS distributions. • Cloudera Certified Developer for Hadoop. • Cloudera Certified Administrator for Hadoop. • Spark Certification from Big Data Spark Foundations. • SCJP, OCWCD. • Experience in setting up Hadoop clusters in PROD, DR, UAT , DEV environments.
This entry was posted in Hadoop Cluster Administration, Hadoop Cluster Installation, Uncategorized, Unix. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s