-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply
executable file
·43 lines (37 loc) · 1.16 KB
/
apply
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
use strict;
use DBI;
use Expect;
use FindBin;
use Digest::SHA1 qw(sha1_hex);
my $h=DBI->connect("DBI:mysql::mysql_read_default_file=$FindBin::Bin/.my.cnf");
my $s=$h->prepare(<<SQL);
Select device.*, snippet.command,
(Select command From snippet Where model=device.model And name='<session>') As cmdA,
(Select command From snippet Where model=device.model And name='</session>') As cmdB,
(Select command From snippet Where model=device.model And name='<config>') As cmdX,
(Select command From snippet Where model=device.model And name='</config>') As cmdZ
From device, snippet
Where Not disable And itime is Not Null
And device.model=snippet.model And snippet.name=?
SQL
$s->execute($ARGV[0]);
while(my $r=$s->fetchrow_hashref)
{
print $r->{name}, "\t[", $r->{host}, "]\n" if -t;
my $z=new Expect;
$z->slave->stty(qw(-echo));
$z->raw_pty(1);
$z->log_stdout(0);
$z->restart_timeout_upon_receive(1);
$z->spawn(qw(/usr/bin/plink -batch -i), "$FindBin::Bin/.ssh/cfgather.ppk", "cfgather\@$r->{host}");
$z->send(
$r->{cmdA}."\n".
$r->{cmdX}."\n".
$r->{command}."\n".
$r->{cmdZ}."\n".
$r->{cmdB}."\n");
$z->expect(10);
undef $z;
}
__END__