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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With