LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-03-2009, 05:56 AM   #1
don___quixote
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Rep: Reputation: 0
expect script output


Hi,

total noobian here: trying to right an expect script to log-in to a router with ssh and retrieve some stats to a log file, however i seem to loose the output passed the password stage.

I relaise there is a fair ammount online regarding this, and apologies for covering old ground, but i seem to be totally failing to get my head around it thus i was hoping someone could spell it out.

Here is the code i am using so far:


#!/usr/bin/expect

spawn ssh -p1022 SUPERUSER@x.x.x.x

expect "SUPERUSER@192.168.128.2'2 password:"

send "XXXXX\r"

send "rept-opstat-pon:on-1-1-1-2:::noreset;\r"

send ^C


and the output i get is:

spawn ssh -p 1022 SUPERUSER@x.x.x.x
SUPERUSER@x.x.x.x's password:



I have experimented with expect_out and exp_send to no avail.


Any help would be great.


Thanks in advance.

Rob
 
Old 07-03-2009, 06:09 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Hi Rob,

welcome to LQ.

To me it seems like your scripts hold when ssh expects a password
Quote:
Originally Posted by don___quixote

and the output i get is:

spawn ssh -p 1022 SUPERUSER@x.x.x.x
SUPERUSER@x.x.x.x's password:
So you either need to setup password less ssh login or use the sshpass command

http://www.debianadmin.com/sshpass-n...ntication.html

I'd rather go with the password less login through key exchange, but for testing purpose and in a sane enviroment sshpass should do the job

Cherrs Zhjim
 
Old 07-03-2009, 09:40 AM   #3
don___quixote
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Hi Zhjim,

Many thanks - i'm feel like I'm asking for my bum to be wiped here but when i run:

Code:
sshpass -p XXX ssh -p 1022 SUPERUSER@x.x.x.x rept-opstat-pon::pon-1-1-1-2::noreset;

I get:

exec requestfailed on channel 0


any ideas?

Thanks again.

Rob

edit : should ad that withou the command it logs in fine - however the command, and out output of the command, is the crux of the exercise therefore leaving me buggered.

Last edited by don___quixote; 07-03-2009 at 09:58 AM.
 
Old 07-05-2009, 09:40 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Hm I just googled the error message but could not fine anything realy usefull beside using -v -v -v as an option to ssh. This will print more verbose what it's trying to do.
What does the command do if you don't use sshpass but just enter the command when it asks for it?
Does the command itself run flawless on the remote machine? (Trying to see if its the command or the ssh that is bugging)
 
Old 07-06-2009, 04:10 AM   #5
don___quixote
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Hi,

yeah the commands run fine if i seperate them and run them manually. This is the debug from the sshpass:

Code:
OpenSSH_5.2p1, OpenSSL 0.9.8k-fips 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.128.2 [192.168.128.2] port 1022.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version IPSSH-1.12.0
debug1: no match: IPSSH-1.12.0
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: checking without port identifier
debug1: Host '192.168.128.2' is known and matches the DSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: found matching key w/out port
debug1: ssh_dss_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: rept-opstat-pon::pon-1-1-1-2:::noreset;
exec request failed on channel 0

Cheers
 
Old 07-06-2009, 10:24 AM   #6
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
I use ssh to remote log into a machine in almost the same way. Here's my expect line:
Code:
expect "*?assword:*"
You might try that. It seems like expect isn't getting what it wants.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
expect script output saltydog4791 Programming 1 05-27-2008 09:01 AM
problem receiving output from Expect script slinx Linux - Software 4 04-30-2008 09:02 AM
How to write output from expect to a file? johnpaulodonnell Programming 2 06-22-2007 06:07 AM
Expect script - No output to file pandersson61 Programming 4 05-23-2007 06:18 AM


All times are GMT -5. The time now is 04:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration