Skip to content

Instantly share code, notes, and snippets.

@hectorgool
Created March 29, 2017 21:50
Show Gist options
  • Select an option

  • Save hectorgool/9f8d1434c3042cdb453a489915a250bd to your computer and use it in GitHub Desktop.

Select an option

Save hectorgool/9f8d1434c3042cdb453a489915a250bd to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Tabla «public.centro»
# Columna | Tipo | Modificadores
# ---------------+-----------------------------+------------------------
# id | integer | not null
# ip | character varying(15) | not null
# hostname | text | not null
# nombre | text |
# alias | character varying(50) |
# razon_social | character varying(254) |
# estado | character varying(30) |
# municipio | character varying(60) |
# colonia | character varying(60) |
# cp | character varying(5) |
# calle | character varying(60) |
# num_ext | character varying(30) |
# num_int | character varying(30) |
# lat | character varying(30) |
# long | character varying(30) |
# dirgmaps | text |
# iva | numeric(10,3) | valor por omisión 16
# rfc | character varying(20) |
# desde | date |
# hora_apertura | time without time zone |
# hora_cierre | time without time zone |
# pcs_usuario | integer |
# pcs_operacion | integer |
# key_gmaps | text |
# activo | boolean | valor por omisión true
# created_at | timestamp without time zone |
# updated_at | timestamp without time zone |
# alias_reporte | text |
# zona_id | integer |
use DBI;
system("clear");
my $dbh = DBI->connect("DBI:Pg:dbname=$ENV{'BDS_DATABASE'};host=$ENV{'BDS_HOST'}", "$ENV{'BDS_USER'}", "$ENV{'BDS_PASSWD'}", {'RaiseError' => 1});
$tipo_servidor=5;
$sth = $dbh->prepare(" SELECT ip,alias,hostname,nombre,activo FROM centro WHERE activo = true ");
$sth->execute();
$contador=0;
while ( $row = $sth->fetchrow_hashref ) {
#$alias= uc $row->{alias};
#print "$row->{ip}\t$alias\n";
$contador++;
my ($octeto1, $octeto2, $octeto3, $octeto4) = split /\./, $row->{ip};
$ip = "$octeto1\.$octeto2\.$octeto3\.$tipo_servidor";
print "# $contador) $row->{nombre}\n";
#$comando = "ssh root\@$ip perl -p -i -e 's/fw16-$row->{alias}/fw-$row->{alias}/g' /etc/hosts\n";
#$comando = "ssh -o \"StrictHostKeyChecking no\" root\@$ip cat /etc/hosts\n";
$comando = "ping $ip\n";
print "$comando";
print `$comando`;
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment