[Libssh] How to run remote interactive shell
naveen tyagi
subs_naveen at yahoo.com
Mon Oct 1 01:16:59 CEST 2007
Hi,
I am trying to use libssh for executing some commands on cisco routers:
I use channel_write to execute the command
but fail to get the output using channel_read. I use a select call on session file descriptors before using channel_read. It fails to get the command output.
Here is the outline of my code
options=ssh_options_new();
if(ssh_options_getopt(options,&argc, argv))
usage();
opts(argc,argv);
signal(SIGTERM,do_exit);
if(user)
ssh_options_set_username(options,user);
ssh_options_set_host(options,host);
session=ssh_new();
ssh_set_options(session,options);
ssh_set_verbosity(-1);
ssh_connect(session)
auth=ssh_userauth_autopubkey(session);
No problem up to this point
Now I open channel and shell
channel=channel_new(session);
channel_open_session(channel);
channel_request_pty(channel);
channel_request_shell(channel);
memset(buffer,0,1024);
memcpy(buffer,routerCmnd[k],strlen(routerCmnd[k]));
buffer[strlen(routerCmnd[k])]=13;
printf("Writing command = %s\n",buffer);
channel_write(channel,(void*)buffer,strlen(routerCmnd[k])+1);
Please note that I do use carriage return;
Then I use channel read after doing a select call on fd associated with session
and all I get to see is the command that I sent for execution and not its output.
Not sure what is missing.
Please help.
Thanks,
Naveen.
---------------------------------
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.cerkinfo.be/pipermail/libssh/attachments/20070930/ef700e06/attachment.htm
More information about the Libssh
mailing list