armcinto has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a simple script that will ssh to and execute a command on a Cisco CallManager server. I can see that I'm authenticating and logging in to the CLI of the server, but I can't get the command to execute. I've tried multiple variations, but nothing is working.

I'm using strawbery perl on an XP machine, the CallManager server is running linux but I'm logging into a CLI (not the linux shell).


my $channel = $ssh->channel(); $channel->execute("show account"); my $output;<br> $channel->read($output,1028); print "output:\n $output\n";

The output that is returned;
output:
Command Line Interface is starting up, please wait ...

This line is what the CLI prints after you successfully login, so the authentication and creating the channel appears to be working.
I have tried ssh debug, and get the following;


libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type, window_size, packet_size, ((void *)0) , 0 ) -> 0x15cc17c
Net::SSH2::Channel::read(size = 1028, ext = 0)
- read 55 bytes
- read 1 bytes
- read 2 bytes
- read 0 bytes
- read 58 total
output:
Command Line Interface is starting up, please wait ...


Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x9de1cc


I don't see any debug statement for the exec. I've also tried to create shell (with and without blocking(0/1) and then write the command, but get pretty much the same result.
I also know that this same script will work when connected to a Cisco IOS router/switch, so I know it's something with the CLI on the server. I'm just hoping there is a way to get it to work.

Any help would be appreciated, I don't know what else to try at this point.


-Aric

Replies are listed 'Best First'.
Re: ssh2 channel/exec issue
by armcinto (Initiate) on Jul 23, 2013 at 23:55 UTC

    After much testing and log review I finally figured this out. I previously tried creating a non-blocking shell, and then writing to the shell, but was getting the same result as the above code. From looking through logs on CUCM I did notice that the script was creating tty=unknown shell. After setting the tty (->pty(1)), I was finally able to work everything out.

    my $channel = $ssh2->channel(); $channel->blocking(0); $channel->pty(1); #set tty $channel->shell(); sleep 10; #required as the CUCM CLI is slow to start $channel->write("show account\n"); sleep 5; #Again the CLI is kind of slow my $output; $channel->read($output,128); print "Account details:\n $output\n";