I updated the script with the construction you suggested but the output was the same. I also noticed that there was an "I" missing from the sed statement and added it. Script:
my $cmd = qq(ssh -qv $ssh_user\@$bkp_destination 'sed -i "s#.*$hostnam +e#$skey#gI" /tmp/test.txt'); warn "Launching [[$cmd]]"; system($cmd) == 0 or die "Couldn't launch ssh connection via +[[$cmd]]: $? / $!";
Output:
debug1: pledge: network debug1: Sending environment. debug1: Sending env LANG = en_GB.UTF-8 #ssh-rsa AAAAB3NzaC1yc2 root@HOSTA#g" /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 51671.7, received 37318.5 debug1: Exit status 0
From the $bkp_destination host:
user@bkphost:/tmp$ cat test.txt As123312123 asdasdadasqsef3w4rfweweweffwerfew As123312123 asdasdadasqsef3w4rfweweweffwerfew i12311231231231 HOSTA As123312123 asdasdadasqsef3w4rfweweweffwerfew user@bkphost:/tmp$ echo $h HOSTA user@bkphost:/tmp$ echo $k ssh-rsa AAAAB3NzaC1yc2 root@HOSTA user@bkphost:/tmp$ sed -i "s#.*$h#$k#gI" test.txt user@bkphost:/tmp$ cat test.txt As123312123 asdasdadasqsef3w4rfweweweffwerfew As123312123 asdasdadasqsef3w4rfweweweffwerfew ssh-rsa AAAAB3NzaC1yc2 root@HOSTA As123312123 asdasdadasqsef3w4rfweweweffwerfew

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.