Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: parse /etc/passwd and output it as csv in hundred servers

by thanos1983 (Parson)
on Apr 16, 2018 at 21:01 UTC ( [id://1213026]=note: print w/replies, xml ) Need Help??


in reply to Re^4: parse /etc/passwd and output it as csv in hundred servers
in thread parse /etc/passwd and output it as csv in hundred servers

Hello garcimo,

There are plenty of reasons that the script that I told you could fail. I will explain just the basic ones:

1) Are you sure that all the nodes (190) have ssh keys generated and the ssh-agent is added? If not follow this perfect tutorial from gitHub Generating a new SSH key and adding it to the ssh-agent. 2) Are you sure that the password that you provide is correct? I mean if you have special characters inside your password it could fail. You need to escape special characters e.g. \@, \$, \_ etc etc...make sure your password is correct. 3) Firewall, are you sure that you can ssh to all nodes? Many other reasons I could add here but there is no point, I would suggest that first make sure that you can ssh to all nodes, all nodes have generated ssh-keys, the agents are added and all can communicate with the main node.

I put a small script that assumes that all the information is correct and checked and then it does the rest for you. It will ssh-copy-id for each node from main to the rest of the nodes and in case of either success or error it will print the output for you, so you can identify the node with the problem. Keep in mind that this is a minimum sample of script, you should hash the output of each node so you can identify the problem easier, or maybe some nodes will fail some will pass etc...etc...

#!/usr/bin/perl use Expect; use strict; use warnings; use Data::Dumper; my $path_to_file = "test.txt"; open my $handle, '<', $path_to_file or die "Could not open file '".$path_to_file."': $!"; chomp(my @devices = <$handle>); close $handle or warn "Could not close '".$path_to_file."': $!"; # print Dumper \@devices; my @params; my $username = "user"; my $ssh_copy_id = "ssh-copy-id ".$username."\@"; my $password = "password"; # These is to bypass the foreach my $device (@devices) { # create an Expect object by spawning another process my $command = join('', $ssh_copy_id, $device); # print $command . "\n"; my $session = Expect->spawn($command) or die "Error calling external program: $!"; my $output; $session->expect(10, [ qr/passphrase/i, sub { my $self = shift; $self->send("$password\n"); exp_continue; }], [ qr/my comments/i, sub { my $self = shift; $output = $self->exp_before; exp_continue; }], ); print $output . "\n" if $output; $session->soft_close; }

In case that all of that is too much work for you and you decide that you want to proceed with simple password procedure (for my point of view you should not) there is an old question that I raised that I was testing multiple ways on doing that and even applying sudo commands see here Best module to execute administrator commands on external operating systems (Linux), similar with the ssh parrallel module Net::OpenSSH::Parallel with sudo commands.

In case that you come across other problems I would suggest raise another question, because this question is not related with other problems. :)

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-16 19:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found