I have a bash script that restores my database. The database is on a remote Linux server, and my Java code is on Windows. How can I run the script?
2 Answers
What do you mean by restore? If you want just load dump of your DB maybe create backup DB and then just copy rows to target database. If you really need to run this scrip easiest way will be to connect to remote server via ssh and launch that script. Use Putty or some ssh java lib to make a connection and send command to run. More info about putty here
2 Comments
user506246
I used Putty to make connection but i dont know how to send command from Java to run.
Try something like this:-
Process p = Runtime.exec("ssh myhost");
PrintStream out = new PrintStream(p.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream());
out.println("ls -l /home/me");
while (in.ready()) {
String s = in.readLine();
System.out.println(s);
}
out.println("exit");
p.waitFor();
From the source thread
1 Comment
user506246
I modified the script and i successfully login to remote machine. But still cannot execute the script, neither linux command.