Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: Send password in Net::SSH::Expect

by Corion (Pope)
on Jan 23, 2020 at 09:36 UTC ( #11111761=note: print w/replies, xml ) Need Help??


in reply to Re^5: Send password in Net::SSH::Expect
in thread Send password in Net::SSH::Expect

warn "Launching [[$cmd]]";

I don't see the output of that anywhere in your output, yet this is the thing that is giving you problems.

If you don't see what is wrong in your local output, maybe share that output with us?

Also, when you run the commands manually, why do you do:

echo $h echo $k sed -i "s#.*$h#$k#gI" test.txt

when the command you are having trouble with is something else?

sed -i "s#.*HOSTA#ssh-rsa AAAAB3NzaC1yc2 root@HOSTA#gI" /tmp/test.txt

Try to bring your manual interaction as close to the scripted interaction as possible. Only then you can see where the difference is between the two things that makes one fail and one succeed.

Replies are listed 'Best First'.
Re^7: Send password in Net::SSH::Expect
by gafaman (Novice) on Jan 23, 2020 at 09:58 UTC
    I couldn't find that in the output as well, not sure why. when I run it manually, I am declaring the variables first and running the sed command as it is done by the script, with the variables. I only used the "echo" commands to show their contents. Running it with the variable contents also works fine, by the way.
    Please find below the full output. #ssh-rsa AAAAB3NzaC1yc2 root@HOSTA#gI" /tmp/test.txt']] at ./key.pl li +ne 70. OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug1: Connecting to 10.11.12.13 [10.11.12.13] port 22. debug1: Connection established. debug1: identity file /opt/spectrum/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /opt/spectrum/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_6 +.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug1: Authenticating to 10.11.12.13:22 as 'triple-n' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256@libssh.org debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: aes128-ctr MAC: umac-128-etm@opens +sh.com compression: none debug1: kex: client->server cipher: aes128-ctr MAC: umac-128-etm@opens +sh.com compression: none debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16 debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:k0DWcaruzakooNGMgJ +dC/MR4hdqsXJhVx195BC/d1VM debug1: Host '10.11.12.13' is known and matches the ECDSA host key. debug1: Found key in /opt/spectrum/.ssh/known_hosts:13 debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_SERVICE_ACCEPT received |-----------------------------------------------------------------| | This system is for the use of authorized users only. | | Individuals using this computer system without authority, or in | | excess of their authority, are subject to having all of their | | activities on this system monitored and recorded by system | | personnel. | |-----------------------------------------------------------------| debug1: Authentications that can continue: publickey,password,keyboard +-interactive debug1: Next authentication method: publickey debug1: Offering RSA public key: /opt/spectrum/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 279 debug1: Authentication succeeded (publickey). Authenticated to 10.11.12.13 ([10.11.12.13]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: network debug1: Sending environment. debug1: Sending env LANG = en_GB.UTF-8 #ssh-rsa AAAAB3NzaC1yc2 root@HOSTA#gI" /tmp/test.txt debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: client_input_channel_req: channel 0 rtype eow@openssh.com repl +y 0 debug1: channel 0: free: client-session, nchannels 1 Transferred: sent 3312, received 2392 bytes, in 0.1 seconds Bytes per second: sent 43267.6, received 31248.8 debug1: Exit status 0
      Please find below the full output. #ssh-rsa AAAAB3NzaC1yc2 root@HOSTA#gI" /tmp/test.txt']] at ./key.pl li +ne 70.

      If that is really, really the (start of the) output of your script, then the hostname (maybe) contains a newline or a carriage return or some other whitespace. Have you really, really checked that your variables contain what you think they do?

      If the file contains Windows newlines for example, the output will look as above, as the carriage return left over from the \r\n sequence will move the cursor to the start of the line again.

        It is really the (important) part, yes. In full:
        user@host:~/scripts$ ./key.pl Scalar value @hostname_check_arr[1] better written as $hostname_check_ +arr[1] at ./key.pl line 44. Scalar value @words[1] better written as $words[1] at ./key.pl line 50 +. Scalar value @key_check_arr[1] better written as $key_check_arr[1] at +./key.pl line 61. #ssh-rsa AAAAB3NzaC1yc root@EXBOLB4-NO1#gI" /tmp/test.txt']] at ./key. +pl line 70. OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for *
        I have checked the variables and they seem to be fine, do you have any specific code in hand to clear them from that sort annoyance?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11111761]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2020-05-30 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?