I am quite new to Ubuntu and shell programming. I am using putty to execute vmstat and iostat commands on Ubuntu. I need to execute those commands in java (Windows environment) and get an InputStream of the result. Is it possible?
            Asked
            
        
        
            Active
            
        
            Viewed 1,653 times
        
    -1
            
            
        - 
                    try using jsch and a shell channel – Scary Wombat Mar 10 '15 at 05:50
 - 
                    Not via putty, no. You'll need to use a library to connect via SSH to the machine. Also, not sure but you should check whether these commands expect a terminal; my guess is that they do, but I may be wrong. – fge Mar 10 '15 at 05:50
 - 
                    I've had success with Jsch, but I suggest making sure your understanding of streams is solid before doing any networking applications. – MeetTitan Mar 10 '15 at 06:01
 - 
                    You can use Runtime class to execute any native code (i.e command line commands) in java and parse the input/output stream. However, as suggested above, using a java library would be better to open an ssh connection and parsing it;s output. – Sanket Meghani Mar 10 '15 at 06:16
 
1 Answers
2
            
            
        Yes. Use plink (a command-line interface to the PuTTY back end).
plink remote_host "ls -l"
I've successfully used this to, from a Windows-based TFS Build, execute an Android build on a Linux box. So it's possible to work with the output from plink programatically.
Here's an example of how to call a shell command from within Java.