|< 1 2 >| | 15 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
ich arbeite an 3 Routers: die die folgenden Daten haben
R-Id Name Ip Pwd
1 r1 20.100.2.100 router
2 r2 20.100.2.99 router
3 r3 20.100.2.80 router
ich wollte mittela der While schleife aller router durchsuchen und jedesmal die update in meinem unteren code Führen
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
#!/usr/bin/perl -w
#DatenbankAbfragen
use strict;
use warnings;
use DBI;
use Net::Telnet::Cisco;
our $dbh;
my $session = Net::Telnet::Cisco-> new (Host => '10.200.2.105');
While('R-id','Name','ip','pwd'){
sub get Router{
my $name=shift;
my $ip=shift;
my $user=shift;
my $pwd=shift;
my ($query,$sth,$sth1,$execu,$newdata,$ds,$summe);
$query = "UPDATE GATE_STATE SET STATE.Time=NOW() WHERE STATE.Name='$name' ORDER BY STATE.Time DESC LIMIT 1";
$sth1=$dbh->prepare($query) or die "Querry Error prepare: $DBI::errstr\n";
$sth1->execute or die "Querry Error execute: $DBI::errstr\n";
$sth->finish();
}
}
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
44
45
46
47
48
49
50
51
#!/usr/bin/perl -w
#DatenbankAbfragen
use strict;
use warnings;
use DBI;
use Net::Telnet::Cisco;
our $dbh;
my $session = Net::Telnet::Cisco-> new (Host => '10.200.2.105');
####################Verbindung##############
open(DAT, '<','../gate_common/MySQLAccount.txt') or die"Could not open SQL-Data-file!";
$raw_data=<DAT>;
close(DAT);
chomp $raw_data;
my ($host,$user,$pass,$db) = split(/:/, $raw_data);
print "host ".$host."\n"."user ".$user."\n"."pass ".$pass."\n"."db ".$db."\n";
$dbh = DBI->connect("DBI:mysql:".$db.":".$host,$user,$pass) or die "Connect Error: $DBI::errstr()\n";
getRouter ('1','r1','20.100.2.100' ,'router');
$dbh->disconnect;
##########################################
sub get Router{
my $name=shift;
my $ip=shift;
my $user=shift;
my $pwd=shift;
my ($query,$sth,$sth1,$execu,$newdata,$ds,$summe);
$query = "UPDATE GATE_STATE SET STATE.Time=NOW() WHERE STATE.Name='$name' ORDER BY STATE.Time DESC LIMIT 1";
$sth1=$dbh->prepare($query) or die "Querry Error prepare: $DBI::errstr\n";
$sth1->execute or die "Querry Error execute: $DBI::errstr\n";
$sth->finish();
$query="SELECT Router.ID, Router.Name,Router.TS,Router.State,Router.conf FROM Router WHERE Router.Name=$name ORDER BY Router.ID DESC LIMIT 1";
$sth = $dbh->prepare($query) or die "Error in query prepare: $DBI::errstr\n";
$sth->execute or die "Error executing query: $DBI::errstr\n";
$sth->finish();
}
getRouter ('1','r1','20.100.2.100' ,'router');
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
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w
#DatenbankAbfragen
use strict;
use warnings;
use DBI;
use Net::Telnet::Cisco;
our $dbh;
my $session = Net::Telnet::Cisco-> new (Host => '10.200.2.105');
####################Verbindung##############
open(DAT, '<','../gate_common/MySQLAccount.txt') or die"Could not open SQL-Data-file!";
$raw_data=<DAT>;
close(DAT);
chomp $raw_data;
my ($host,$user,$pass,$db) = split(/:/, $raw_data);
print "host ".$host."\n"."user ".$user."\n"."pass ".$pass."\n"."db ".$db."\n";
$dbh = DBI->connect("DBI:mysql:".$db.":".$host,$user,$pass) or die "Connect Error: $DBI::errstr()\n";
getRouter ('1','r1','20.100.2.100' ,'router');
$dbh->disconnect;
##########################################
sub get Router{
my $name=shift;
my $ip=shift;
my $user=shift;
my $pwd=shift;
my @output
my ($query,$sth,$sth1,$execu,$newdata,$ds,$summe);
$query = "UPDATE GATE_STATE SET STATE.Time=NOW() WHERE STATE.Name='$name' AND IP='$ip' ORDER BY STATE.Time DESC LIMIT 1";
$sth1=$dbh->prepare($query) or die "Querry Error prepare: $DBI::errstr\n";
$sth1->execute or die "Querry Error execute: $DBI::errstr\n";
$sth->finish();
$query = "INSERT INTO Router(ID,Name,IP,State,Config) VALUES ('','$name',$ip,'UP','@output')";
$sth1 = $dbh->prepare($query) or die "Error in query prepare: $DBI::errstr\n";
$sth1->execute or die "Error executing query: $DBI::errstr\n";
$sth->finish();
}
|< 1 2 >| | 15 Einträge, 2 Seiten |