Executing the shell script through java program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing the shell script through java program
# 1  
Old 07-22-2014
Wrench Executing the shell script through java program

Hi Team,

Can you pls advise in java how can we call a shell script, actly I have a shell script at the following location
Code:
/opt/dd/ajh.sh

now I can execute this script by opening the session through putty by entering the servers details and password and then navigating to the following location.....
Code:
opt/dd/ajh.sh

and then exceutig this script ajh.sh start
this script requires an additional parameter 'start' now lets say if my server details are
Code:
userid is XXX
PASSWORD is YYY

now please advise through java program How can I call this script .

Note - that server details like userid and password can be harcoded in java class in string string itself.
# 2  
Old 07-22-2014
By example, google for more...
Code:
Runtime r = Runtime.getRuntime(); 
Process p = r.exec("uname -a"); 
p.waitFor(); 
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream())); 
String line = "";  
while ((line = b.readLine()) != null) {   
System.out.println(line); 
}  
b.Close();

# 3  
Old 07-22-2014
Quote:
Originally Posted by blackrageous
By example, google for more...
Code:
Runtime r = Runtime.getRuntime(); 
Process p = r.exec("uname -a"); 
p.waitFor(); 
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream())); 
String line = "";  
while ((line = b.readLine()) != null) {   
System.out.println(line); 
}  
b.Close();

Hi blackrageous ,

Thanks for the reply , but my major concerns is that java program should first establish he connection with server first how it will make ssh connection first and then it will execute that script , please advise
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compiling and Executing a Java File With a Shell Script

I'm trying to use a shell script to compile and execute a java file. The java classes are using sockets, so there is a client.java file and a server.java file, each with their own shell script. I also want to handle the command line arguments within the shell script, not the java classes. The... (1 Reply)
Discussion started by: britty4
1 Replies

2. Shell Programming and Scripting

Executing java .jar from UNIX script

I have a .jar placed in my Unix directory. The .jar creates a .csv file .I want to execute the .jar and place the output file in a target Unix directory. The Unix Script is as follows. The issue that i am facing is that the file is not being placed in the REPORTDIR=/cdunix/IQNavigator/wrk instead... (4 Replies)
Discussion started by: pankajkargeti12
4 Replies

3. Shell Programming and Scripting

Problem while Invoke Shell Script function from Java Program

Hi, I have create a Shell Script, with one function. I want to call the script file in Java Program. It working fine. but the problem is the function in the Shell Script is not executed. Please suggest me, Regards, Nanthagopal A (2 Replies)
Discussion started by: nanthagopal
2 Replies

4. Shell Programming and Scripting

Shell script to input as if from command line to the java program

Hi, We are having a java server which can run on command line and once initiated, it will prompt options to enter from 0 to 5. The java program kickoff respective operation once number is entered between 0 to 5. However i want to always enter "1" and write another shell program wrapper to start... (4 Replies)
Discussion started by: surya5kn
4 Replies

5. Shell Programming and Scripting

how to execute a unix shell script from a java program

Hi All, well , i am facing this problem.. i have tried a few sample codes but there isn't any solution . could anyone please give a sample code as of how to do this... Please see the below details...and read the details carefully. I have written some code, logic is 1)from... (4 Replies)
Discussion started by: aish11
4 Replies

6. Shell Programming and Scripting

Executing the result of a program as a shell script

I have a program that returns a shell script and I want to execute the script. I'll use cat in my simple example, but wget is an example that is feasible. $ # First setup a script $ echo "ls > df" > simple $ # "cat simple" is now a program that returns a script $ cat simple ls df $ ... (3 Replies)
Discussion started by: kopite
3 Replies

7. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

8. Shell Programming and Scripting

Executing shell program from a web page

Hi, I am looking for a cgi-script which runs a shell script from a web page. When I click "Run" from a web page it should run the shell commands in an textarea and results should get back to web page. Thanks Venkat (5 Replies)
Discussion started by: venkatritch
5 Replies

9. UNIX for Advanced & Expert Users

Advantage of executing program in user shell?

Hi, I'm curious about the advantage of forking and executing a program in a user shell as opposed to forking and executing the program directly without the user shell. For example: why is it often like: SSHD->fork&exec(shell, sftp-server)->fork&exec(sftp-server) And Not like: ... (2 Replies)
Discussion started by: seeker333
2 Replies

10. UNIX for Dummies Questions & Answers

executing the su command from a java program.

Say in unix (AIX) m/c, I am logged in with s1 user and want to start process p1 with user credentials of s2. I can do manually in this way: #su - s2 #enter password for s2> somePassword $ p1 But all this I have to do through a java program. How to pass the password through program. One... (1 Reply)
Discussion started by: shailendrat
1 Replies
Login or Register to Ask a Question