I have a shell script like this.
#!/bin/sh
/home/hduser/Downloads/hadoop/bin/stop-all.sh
echo "RUNNING HADOOP PROGRAM"
cd /home/hduser/Downloads/hadoop
sudo rm -R /tmp/*
sudo rm -R /app/*
cd
sudo mkdir -p /app/hadoop/tmp
sudo chown hduser:hadoop /app/hadoop/tmp
sudo chmod 750 /app/hadoop/tmp
hadoop namenode -format
/home/hduser/Downloads/hadoop/bin/start-all.sh
jps
hadoop dfs -mkdir -p ~/Downloads/hadoop/input
hadoop dfs -copyFromLocal /home/hduser/Desktop/iris.arff ~/Downloads/hadoop/input
hadoop jar ~/Desktop/try.jar 2 weka.classifiers.trees.J48 ~/Downloads/hadoop/input ~/Downloads/hadoop/output
/home/hduser/Downloads/hadoop/bin/stop-all.sh
I am invoking this script in my java program like this
public class UIinput
{
public static void main(String[] args) throws IOException
{
// Runtime.getRuntime().exec("/home/hduser/Desktop/initial.sh");
new ProcessBuilder("/home/hduser/Desktop/initial.sh");
ProcessBuilder pb = new ProcessBuilder("/home/hduser/Desktop/initial.sh");
Process process=pb.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:",
Arrays.toString(args));
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
}
}
My start-all.sh,stop-all.sh and echo commands That are getting executed present in the script are getting executed but other commands are not.My output is like
Output of running [] is:no jobtracker to stop
localhost: no tasktracker to stop
no namenode to stop
localhost: no datanode to stop
localhost: no secondarynamenode to stop
RUNNING HADOOP PROGRAM
starting namenode, logging to /home/hduser/Downloads/hadoop/libexec/../logs/hadoop-hduser-namenode-ubuntu.out
localhost: starting datanode, logging to /home/hduser/Downloads/hadoop/libexec/../logs/hadoop-hduser-datanode-ubuntu.out
localhost: starting secondarynamenode, logging to /home/hduser/Downloads/hadoop/libexec/../logs/hadoop-hduser-secondarynamenode-ubuntu.out
starting jobtracker, logging to /home/hduser/Downloads/hadoop/libexec/../logs/hadoop-hduser-jobtracker-ubuntu.out
localhost: starting tasktracker, logging to /home/hduser/Downloads/hadoop/libexec/../logs/hadoop-hduser-tasktracker-ubuntu.out
stopping jobtracker
localhost: stopping tasktracker
no namenode to stop
Can anyone help me?I when I run my java code i want all of the commands to be executed in the shell script.
Thank you