One of the scripts I have is a sample.js script that allows me to view files located on the server myHost. It works perfectly:
var exec = require('ssh-exec')
var v_host = 'myHost'
exec('ls -lh', {
user: 'username',
host: v_host,
password: 'password'
}).pipe(process.stdout , function (err, data) {
if ( err ) { console.log(v_host); console.log(err); }
console.log(data)
})
Now, I'm attempting to execute system commands from Groovy and want to set the host parameter. However, my sample Groovy script currently only works on the local system and displays files located on the local server:
Process p = Runtime.getRuntime().exec("ls -l")
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder execSb = new StringBuilder();
String line = "";
while ((line = reader.readLine())!= null) {
execSb.append(line + "\n");
}
Is it possible to provide a host parameter to the exec method similar to the JavaScript script?