Looking at the Net::OpenSSH documentation, it says "When a new Net::OpenSSH object is created, the OpenSSH ssh client is run in master mode, establishing a permanent (actually, for the lifetime of the object) connection to the server. Then, every time a new operation is requested a new ssh process is started in slave mode, effectively reusing the master SSH connection to send the request to the remote side."

However, consider the following code (simplified from my actual code to make the problem clearer):

use Net::OpenSSH; $Net::OpenSSH::debug = -1; my $ssh = Net::OpenSSH->new("host.domain", (user => "username", passwo +rd => "password", timeout=>30, master_opts => [-o => "UserKnownHostsF +ile=/dev/null"])); while(1) { my($stdout, $stderr) = $ssh->capture2({timeout => 30}, "sleep +5"); }

Looking at /var/adm/wtmp on host.domain, I see updates with my username every 5 seconds when running this script. Shouldn't it only be once every time I run the script???

The real-life problem I'm encountering is that my script runs about 100 commands on host.domain every day. With one entry added in /var/adm/wtmp for each command, this causes /var to fill up in a few weeks, leading to no one being able to log into host.domain remotely until /var/adm/wtmp is cleaned out, which doesn't make people very happy with me. I nor anyone I know has admin authority to this box (though one person, not me, does have enough authority to clear out /var/adm/wtmp). Is there any way for me to modify my script to prevent this from happening?

Additional info (output when in debug mode):

# ctl_path: /root/.libnet-openssh-perl/username-host.domain-19342-2284 +20, ctl_dir: /root/.libnet-openssh-perl/ # _is_secure_path(dir: /root/.libnet-openssh-perl, file mode: 16832, f +ile uid: 0, euid: 0 # _is_secure_path(dir: /root, file mode: 16832, file uid: 0, euid: 0 # _is_secure_path(dir: /root/.libnet-openssh-perl, file mode: 16832, f +ile uid: 0, euid: 0 # _is_secure_path(dir: /root, file mode: 16832, file uid: 0, euid: 0 # set_error(0 - 0) # call args: ['ssh','-o','UserKnownHostsFile=/dev/null','-xMN','-S','/ +root/.libnet-openssh-perl/username-host.domain-19342-228420','-o','Us +er=username','--','host.domain'] Warning: Permanently added 'host.domain,9.5.252.203' (RSA) to the list + of known hosts. # passwd requested (yes username@host.domain's password:) # call args: ['ssh','-O','check','-S','/root/.libnet-openssh-perl/user +name-host.domain-19342-228420','-o','User=username','--','host.domain +'] # open_ex: ['ssh','-O','check','-S','/root/.libnet-openssh-perl/userna +me-host.domain-19342-228420','-o','User=username','--','host.domain'] + # call args: ['ssh','-S','/root/.libnet-openssh-perl/username-host.dom +ain-19342-228420','-o','User=username','--','host.domain','sleep 5'] # open_ex: ['ssh','-S','/root/.libnet-openssh-perl/username-host.domai +n-19342-228420','-o','User=username','--','host.domain','sleep 5'] # call args: ['ssh','-S','/root/.libnet-openssh-perl/username-host.dom +ain-19342-228420','-o','User=username','--','host.domain','sleep 5'] # open_ex: ['ssh','-S','/root/.libnet-openssh-perl/username-host.domai +n-19342-228420','-o','User=username','--','host.domain','sleep 5'] # call args: ['ssh','-S','/root/.libnet-openssh-perl/username-host.dom +ain-19342-228420','-o','User=username','--','host.domain','sleep 5'] # open_ex: ['ssh','-S','/root/.libnet-openssh-perl/username-host.domai +n-19342-228420','-o','User=username','--','host.domain','sleep 5']
...

In reply to Multiple connections with single Net::OpenSSH object by Only1KW

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.