This is an old revision of the document!
# cat readstdin.pl
#!/usr/bin/perl
while(<>) {
print $_;
if (/^(allow|deny) ([^ ]+) ([^ ]+) ([^ ]+) (.*$)/) {
$act=$1;
$proto=$2;
$src=$3;$dst=$4;$port=$5;
$count++;
print "ipfw -q add $act $proto from $src to $dst $port\n";
}
}
# cat show_cdp_neighbors.pl
#!/usr/bin/perl
use strict;
use warnings;
my ($ip) = @ARGV;
if (not defined $ip) {
die "Need ip\n";
}
my $sw=`snmpget -On -m ALL -c public -v2c $ip sysName.0 2>/dev/null`;
print "neibors for switch: $sw\n";
foreach my $i (`snmpwalk -On -v2c -c public -m ALL $ip .1.3.6.1.4.1.9.9.23.1.2.1.1.6 2>/dev/null`) {
$i=~/.*STRING: (.*)/;
print "$1\n";
}
CREATE TABLE
table1 (
a INT NOT NULL AUTO_INCREMENT,
b INT NOT NULL,
PRIMARY KEY(a)
);
CREATE TABLE
table2 (
b INT NOT NULL,
a INT NOT NULL,
PRIMARY KEY(b)
);
CREATE TABLE
table3 (
b INT NOT NULL,
a INT NOT NULL
);
# cat example3.pl
#!/usr/bin/perl
use DBI;
print "Start\n";
my $dsn = 'DBI:mysql:test:127.0.0.1:3306';
my $db_user_name = 'test';
my $db_password = 'test';
printf "Connect to test\n";
my %attr = (AutoCommit=>0,RaiseError=>1,HandleError => \&DBerror);
my $dbh = DBI->connect($dsn, $db_user_name, $db_password, \%attr);
my $sth = $dbh->prepare(qq{SET NAMES 'utf8'});
$sth->execute() or print "Cannot execute: " . $sth->errstr();
printf "Loop\n";
MAINLOOP:
for (my $c = 10; $c >= 1; $c--) {
my $b = int(rand(10));
$sth = $dbh->prepare(qq{insert into table1 (b) values ($b)});
$sth->execute() or next MAINLOOP;
$sth = $dbh->prepare(qq{select LAST_INSERT_ID()});
$sth->execute() or next MAINLOOP;
(my $a)=$sth->fetchrow_array();
print "a = $a; b = $b\n";
$sth = $dbh->prepare(qq{insert into table2 (b, a) values ($b, $a)});
$sth->execute() or next MAINLOOP;
$sth = $dbh->prepare(qq{insert into table3 (a, b) values ($a, $b)});
$sth->execute() or next MAINLOOP;
$dbh->commit() or next;
}
$sth->finish();
$dbh->disconnect();
exit 0;
sub DBerror(){
my $err = shift;
print "ROLLBACK $err\n";
$dbh->rollback();
}