I'm using Net::OpenSSH module to connect to a node. But while connecting to the node, I need to specify -v for ssh as ssh -v admin#hostname. Tried using master_opts and default_ssh_opts. But they didn't work.
my $ssh = Net::OpenSSH->new("$user_name\:$password\#$server",strict_mode => 0, default_ssh_opts => [-o => "-v"]);
How can this be achieved?
my $ssh = Net::OpenSSH->new($server,
user => $user_name,
password => $password,
strict_mode => 0,
master_opts => ['-v']);
Related
you have an idea on how to solve this problem that I met with the function message_string () of Mail::IMAPClient library, here is my code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;
# Create the object connexion with socket SSL + LOG ON
my $imap = Mail::IMAPClient->new(
#Debug => 1,
User => 'xxxxx',
Password => 'yyyyy',
Uid => 1,
Peek => 1, # set \Seen flag
Socket => IO::Socket::SSL->new(
Proto => 'tcp',
PeerAddr => 'zzzzzzz',
PeerPort => 993,
)
);
die "$0: connect: $#" if defined $#;
my $nm=$imap->unseen_count("INBOX") ;
# Select INBOX dossier
$imap->select("INBOX");
my $msg = $imap->message_string('47') or die " $#\n";
the error obtained is the following:
message_string() expected 304627 bytes but received 304718 you may need the IgnoreSizeErrors option
The error message tells you exactly how to cope with this. Some IMAP servers calculate the message size incorrectly -- in particular, many (such as notably GMail) examine the local message size, then change the line terminators to CRLF when sending the message over IMAP, resulting in a slightly different actual size than what the server told the client to expect. By default, IMAPClient will throw an error when this happens, but you can tell it not to by saying IgnoreSizeErrors => 1 when you create an instance.
my $imap = Mail::IMAPClient->new(
#Debug => 1,
User => 'xxxxx',
Password => 'yyyyy',
Uid => 1,
Peek => 1, # set \Seen flag
Socket => IO::Socket::SSL->new(
Proto => 'tcp',
PeerAddr => 'zzzzzzz',
PeerPort => 993,
),
# See here
IgnoreSizeErrors => 1
);
I am trying to create a ssh handle through module http://search.cpan.org/~salva/Net-OpenSSH-0.62/. I tried setting GSSAPIAuthentication and GSSAPIDelegateCredentials to "No", but these setting don't take effect if my .ssh/config is like this:
$ cat myusername/.ssh/config
Host *
CheckHostIP no
StrictHostKeyChecking no
HashKnownHosts no
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no
UserKnownHostsFile /dev/null
LogLevel ERROR
This is how I try to set GSSAPIAuthentication and GSSAPIDelegateCredentials. Also is there a way to give -F option in open ssh constructor so that by default ssh uses some other config file rather than using the one user my user name?
$self->{ssh} = Net::OpenSSH->new($host,
user => $username,
passwd => $password,
timeout => $timeout,
default_stderr_discard => 1,
kill_ssh_on_timeout => 1,
master_opts => [-o => "UserKnownHostsFile=/dev/null",
-o => "GSSAPIAuthentication=no",
-o => "GSSAPIDelegateCredentials=no",
-o => "StrictHostKeyChecking=no"]);
Just add -F => 'somepath/config' under master_opts:
master_opts => [-F => 'somepath/config']
and another line like this:
$self->{ssh}->{_ssh_opts} = ['-F', 'somepath/config'];'
I run snmptrapd and can see incoming trap, when send trap via snmptrap
snmptrap -c public -v 2c localhost "" 1.3.3.3.3.3.3.3 1.2.2.2.2.2.2 s "Aliens here"
But I no have trap, when send via Perl script
use SNMP;
$sess = new SNMP::Session(DestHost => '127.0.0.1', RemotePort => "162" );
$sess->trap(enterprise=>'.1.3.6.1.4.1.2021', # or 'ucdavis' [default]
agent => '127.0.0.1', # or 'localhost',[dflt 1st intf on host]
generic => specific, # can be omitted if 'specific' supplied
specific => 5, # can be omitted if 'generic' supplied
uptime => 1234, # dflt to localhost uptime (0 on win32)
[[ifIndex, 1, 1],[sysLocation, 0, "here"]]);
What's wrong?
Your second version i.e. the perl one is not specifying community or version, unlike the first one. Try adding them
$sess = new SNMP::Session(DestHost => '127.0.0.1',
RemotePort => "162",
Community => "public,
Version => 2);
Also see http://www.remothelast.altervista.org/SNMP_Perl.html
and http://www.net-snmp.org/docs/perl-SNMP-README.html for SNMP::Session usage.
I want to run the following setup script to configure a postgresql database that's being deployed via a virtual machine, provisioned via vagrant using puppet:
#!/bin/bash -e
sudo su - postgres
createdb testdb
psql -s tm351test -c "create user test password 'test';GRANT ALL PRIVILEGES ON DATABASE testdb TO test;"
touch /root/postgresql.done
My vagrant config takes the form:
package {
[
'postgresql',
'postgresql-client'
]: ensure => latest;
}
file {
'/root/postgresql.setup':
source => 'puppet:///modules/infinite_interns/root/postgresql.setup',
owner => root,
group => root,
mode => '0744';
}
#TO DO - how do we guarantee the postgresql server is running and tools available?
exec {
'setup-postgresql':
cwd => '/root',
command => '/root/postgresql.setup',
creates => '/root/postgresql.done';
}
service {
'postgresql':
ensure => running,
enable => true;
}
Package['postgresql'] -> Service['postgresql']
How do I guarantee that that the postgresql server is installed and running, and the command line tools available, before running the config script?
I'm new to Puppet - does the Exec() not run if the created file postgresql.done exists?
I suspect that the psql command may also expect a confirmatory "return" to execute the command - how would I do that?
There's an official postgresql module that can be easily installed:
puppet module install puppetlabs-postgresql
or adding following to your Puppetfile:
mod 'puppetlabs-postgresql'
The configuration might look like this:
class { 'postgresql::globals':
encoding => 'UTF-8',
locale => 'en_US.UTF-8',
version => '9.6',
}->
class { 'postgresql::server':
ip_mask_deny_postgres_user => '0.0.0.0/32',
ip_mask_allow_all_users => '0.0.0.0/0',
listen_addresses => '*',
version => '9.6',
}
postgresql::server::db { 'testdb':
user => 'test',
password => postgresql_password('test', 'testpassword'),
}
postgresql::server::pg_hba_rule { 'allow connection from ...':
description => "Open up PostgreSQL for access from test domain",
type => 'host',
database => 'testdb',
user => 'test',
address => '.testdomain.com',
auth_method => 'md5',
}
Your best bet is to use the postgres module https://forge.puppetlabs.com/puppetlabs/postgresql
I am new in openLDAP and perl. I want to export /import LDAP data with/without schema from LDAP database. Is this possible to do that using perl script? If yes ,please give me a sample code.
I would like to create a new schema using openLDAP and perl without dns.How to do that?
This is too many questions in one item. Please ask one question at a time.
How to read Ldap from wtih Perl:
use strict;
use warnings;
use Data::Dumper;
### for ldap
use Convert::ASN1;
use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_name canonical_dn ldap_explode_dn ldap_error_text);
use Net::LDAP::LDIF;
my %parms (
host => 'localhost',
port => 389,
binddn => 'your dn',
passwd => 'password',
base => "",
filter => "(objectclass=*)",
scope => "base",
attrs => ['*'],
);
my $ldif = Net::LDAP::LDIF->new( "out.ldif", "w", onerror => 'die', wrap => 0 );
my $ldap= Net::LDAP->new($parms{'host'}, port => $parms{'port'});
my $bind_result = $ldap->bind($parms{'binddn'},'password' => $parms{'passwd'},'version' => '3');
if($bind_result->is_error()) {
die ('Unable to bind to ' . $parms{'host'} . ': '.$bind_result->error());
}
my #search_args = (
'base' => $parms{"base"},
'scope' => $parms{'scope'},
'filter' => $parms{'filter'},
'attrs' => $parms{'attrs'},
'deref' => 'always',
);
my $msg = $ldap->search(#search_args);
if ($msg->is_error()) {
die "ERROR: ".Dumper(\#search_args).", ".$msg->error."\n";
}
while (my $entry = $msg->pop_entry()){
my $cn = $entry->get_value("cn");
print "cn: $cn\n";
}