Thanks Again Keith,
I already could to send multiple commands keeping the Input and Output
streams, but now I have a problem, it looks like in reads in a lot of
garbage and it takes ages for reading the input stream, so executing three
commands It's taking like 4 minutes. Basically what I do is to make the
input and output stream globals and send the commands, like this (Test
code):
ssh.executeMultipleCmds("mkdir /home/emgiraldo/Documentos/pepe");
ssh.executeMultipleCmds("cd /home/emgiraldo/Documentos/pepe/");
ssh.executeMultipleCmds("touch ensayis");
ssh.executeMultipleCmds("echo funciona > ensayis");
public String executeMultipleCmds(String cmd){
StringBuilder readText = new StringBuilder();
try {
ByteBuffer readBuffer = ByteBuffer.allocate(1);
try {
output.write((cmd+"\n").getBytes());
output.flush();
while(input.available() > 0){
int i = input.read(readBuffer.array(), 0, 1);
if (i < 0) {
break;
}
}
//System.out.println(readText.toString());
return readText.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
What is the best way for managing the input and output streams? or what do
you recommend me to do this?
Thanks a lot.
On Fri, Dec 2, 2011 at 12:43 PM, Ram Panguluri <ram.pangul...@aptare.com>wrote:
> Use the Shell as explained in the link:
> http://sites.google.com/site/javabidev/Home/jsch
>
> On Dec 2, 2011, at 4:26 AM, Erik Michel Giraldo Giraldo wrote:
>
> Hello Keith, Thanks for the answer.
>
> Actually the commands I have to do are going to be executed in a Fortigate
> CLI, so I can not send them like that, what I need to do is:
>
> (fotigatesrv)#configure global
> (fotigatesrv)(global)#execute .... ... ....
>
> And the fortigate cli does not accept multiple commands in the same line.
> Any ideas?
>
> Thanks!!!
>
>
> On Fri, Dec 2, 2011 at 12:41 AM, Keith Alan Richardson <
> keith.a...@gmail.com> wrote:
>
>> One option if those are the only commands you need: ls /var/log
>>
>> On Dec 1, 2011 10:42 PM, "Erik Michel Giraldo Giraldo" <
>> erikumaniza...@gmail.com> wrote:
>>
>> Hello,
>>
>> Right now I need to execute multiple commands in single session, it has
>> to be executed in a Fortigate OS, it does not allow me to execute it with
>> ";" between commands, so I need to execute them like you normally do.
>> Something like this:
>>
>> root@localhost$ cd /var/log/
>> root@localhost$ ls
>>
>> Which should return the files in log.
>>
>> Thanks for your great help.
>>
>> --
>>
>> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>> Cordialmente;
>>
>> Erik Michel Giraldo Giraldo
>>
>> ****Por favor considere su responsabilidad ambiental antes de imprimir
>> este correo.****
>>
>>
>>
>> ------------------------------------------------------------------------------
>> All the data continuously generated in your IT infrastructure
>> contains a definitive record of customers, application performance,
>> security threats, fraudulent activity, and more. Splunk takes this
>> data and makes sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-novd2d
>> _______________________________________________
>> JSch-users mailing list
>> JSch-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jsch-users
>>
>>
>>
>
>
> --
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Cordialmente;
>
> Erik Michel Giraldo Giraldo
>
> ****Por favor considere su responsabilidad ambiental antes de imprimir
> este correo.****
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
>
> http://p.sf.net/sfu/splunk-novd2d_______________________________________________
> JSch-users mailing list
> JSch-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jsch-users
>
>
> RAM PANGULURI
> ram.pangul...@aptare.com
>
>
>
>
--
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Cordialmente;
Erik Michel Giraldo Giraldo
****Por favor considere su responsabilidad ambiental antes de imprimir este
correo.****
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users