Skip to content

Instantly share code, notes, and snippets.

@ayushgp
Created November 28, 2016 09:00
Show Gist options
  • Save ayushgp/a33d77eec85a3aad8ffc3fb2648691e8 to your computer and use it in GitHub Desktop.
Save ayushgp/a33d77eec85a3aad8ffc3fb2648691e8 to your computer and use it in GitHub Desktop.
# Format the namenode
bin/hadoop namenode -format
# Start hadoop related processes
sbin/start-dfs.sh
sbin/start-yarn.sh
# Create input directory and put relavent text file in it
echo "Creating input directory $1 and putting textfile.txt on it."
bin/hadoop fs -mkdir $2
bin/hadoop fs -put ../textfile.txt $2
# Compile the Map reduce job
echo -e "\nCompiling $1.java\n\n"
bin/hadoop com.sun.tools.javac.Main $1.java -Xlint
echo -e "\nCreating jar for given job\n\n"
jar cf wc.jar $1*.class
echo -e "\nExecuting the Map Reduce Job on HDFS\n\n"
bin/hadoop jar wc.jar $1 $2 $3
# Direct output to given file
bin/hadoop fs -cat $3/part-00000 > final_output.txt
echo -e "\nStopping hadoop related processes\n"
sbin/stop-dfs.sh
sbin/stop-yarn.sh
echo -e "\nThe Output has been saved to final_output.txt file\n"
gedit final_output.txt
# Provide the arguments to shell script as:
# run-map-reduce-job.sh WordCount /input /output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment