Only1KW has asked for the wisdom of the Perl Monks concerning the following question:
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']
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple connections with single Net::OpenSSH object
by salva (Canon) on Sep 29, 2009 at 19:10 UTC | |
by Anonymous Monk on Sep 29, 2009 at 21:42 UTC | |
by salva (Canon) on Sep 30, 2009 at 06:50 UTC | |
|
Re: Multiple connections with single Net::OpenSSH object
by Illuminatus (Curate) on Sep 29, 2009 at 19:31 UTC |