How to connect to unix server and perform operation in java as we performed in unix screen. I wnat to execute this command "sed '1,2d;/affected/d;/^$/d;/------/d'" in java.
Asked
Active
Viewed 138 times
-1
-
Do you want to execute the command in the local machine or a remote one? – Javier Mar 13 '13 at 11:26
-
1Have a look at http://stackoverflow.com/questions/995944/ssh-library-for-java – Pradheep Mar 13 '13 at 11:26
-
1want to execute in remote one – user2160534 Mar 13 '13 at 11:28
1 Answers
1
These are actually two questions.
How to execute a system command in Java. For that you can use Runtime.exec
Process p = Runtime.getRuntime().exec("sed '1,2d;/affected/d;/^$/d;/------/d' file.txt");
p.waitFor();
How to execute a command on a remote machine. This could be done with ssh
ssh user@example.com "sed '1,2d;/affected/d;/^$/d;/------/d' file.txt"
For that to work, you must have ssh
installed, of course.

Olaf Dietsche
- 72,253
- 8
- 102
- 198