Reputation: 281
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?
Upvotes: 3
Views: 1777
Reputation: 172558
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
Upvotes: 1
Reputation: 6371
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
Upvotes: 1