commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de>
Subject Re: Execute ssh command and input password upon prompt
Date Wed, 20 Jun 2012 12:09:47 GMT
You need to parse the output and feed the input stream to the
PumpStreamHandler you give to commons-exec with your password.
I use this too to get a password to a tool like this:

      ...
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      byte[] bpass = password.getBytes();
      ByteArrayInputStream bin = new ByteArrayInputStream(bpass);
      
      // executor
      DefaultExecutor executor = new DefaultExecutor();
      executor.setProcessDestroyer(processDestroyer);
      
      // stream handler
      PumpStreamHandler streamHandler = new PumpStreamHandler(baos,baos,
bin);
      executor.setStreamHandler(streamHandler);
      ...
      executor.execute(commandLine);
      ...

In this example no "parsing" of stdout or something else is done to
"know" when to feed the password to stdin - in my usecase stdin is ONLY
used to provide the password and no other input will be accepted and or
read by the destination application and i do not need to wait for
anything "happen" on stdout.
The tool will prompt at some time for the pass and read from stdin to
get it and the handler does provide the inputstream above, thats it.

HTH.

regards

Torsten


Am Dienstag, den 19.06.2012, 16:14 +0100 schrieb Brendan Crowley:
> Hi All,
> 
>  
> 
> I'm looking to write a java utility that will execute a "ssh -t -t user@host
> mysqldump -uuser -ppw db table" the other command after the ssh will return
> the result to standard output.
> 
>  
> 
> The ssh command results in a prompt for a Password, i would try to avoid
> shared keys in my implementation, how can i setup apache common exec to
> execute the above command and automatically input the password when
> prompted?
> 
>  
> 
> Regards,
> 
> Brendan
> 
>  
> 
> 
> 
> 
> 


Mime
View raw message