App-Goto2

 view release on metacpan or  search on metacpan

lib/App/Goto2.pm  view on Meta::CPAN


    my $hostre = join '.*', @{ $self->extra_argv };

    error("Must supply string to match host(s)") unless $hostre or $self->list;

    my $hosts = $self->hosts;

    my @matching_hosts = grep { m/$hostre/ } sort keys %$hosts;

    error("No matching hosts found") unless @matching_hosts;
    say "Hosts found: @matching_hosts" if $self->verbose;
    # Just print a list of servers if appropriate
    $self->print_list(\@matching_hosts) if $self->list;

    # Either iterate over all matching hosts, or just use the first
    for my $host ( @matching_hosts ) {
        my $cmd = $self->generate_ssh_cmd($hosts->{$host});
        say "Executing command: $cmd" if $self->verbose;
        system( $cmd );
        exit unless $self->iterate;
    }
}

sub get_aws {
    my ($self) = @_;

    use Net::Amazon::EC2;

lib/App/Goto2.pm  view on Meta::CPAN

    # Over-write the local config
    $self->config_hosts(\%hosts);
}

sub print_list {
    my ($self, $hostnames) = @_;

    my $hosts = $self->hosts;

    for my $host (@$hostnames) {
        say "$host: " . $hosts->{$host}{hostname};
        }
    exit;
}

sub generate_ssh_cmd {
    my ($self, $host) = @_;

    my $cmd = 'ssh ';

    $cmd .= ' -p ' . $host->{port} . ' ' if $host->{port};

lib/App/Goto2.pm  view on Meta::CPAN

    $cmd .= ' ' . $host->{user} . '@' if $host->{user};
    $cmd .= $host->{hostname};

    $cmd .= " '" . $self->{cmd} . "'" if $self->{cmd};

    return $cmd;
}

sub error {
    my ($msg) = @_;
    say $msg;
    exit 1;
}

sub hosts {
    my ($self) = @_;
    $self->config_hosts( $self->_config_data->{hosts} ) unless $self->config_hosts;
    return $self->config_hosts
}

1;



( run in 0.631 second using v1.01-cache-2.11-cpan-96521ef73a4 )