#!/usr/bin/perl -w use strict; use warnings; use Date::Manip; # Convert to EPOCH my $ptime = ParseDate("now"); print "PTIME: \"$ptime\"\n"; my $sepoch = UnixDate($ptime,"%s"); print "SEPOCH: \"$sepoch\"\n"; #$dtime = UnixDate($ptime, "%Y-%m-%d %H:%M:%S"); #print "DTIME: \"$dtime\"\n"; # Convert it back my $date = ParseDateString("epoch $sepoch"); print "DATE: \"$date\"\n"; my $ndtime = UnixDate($date, "%Y-%m-%d %H:%M:%S"); print "NDTIME: \"$ndtime\"\n"; exit; #### PTIME: "2014020918:06:03" SEPOCH: "1391987163" DATE: "2014020918:06:03" NDTIME: "2014-02-09 18:06:03" #### $query = undef; $sth = undef; $ect = 0; @row = (); $macidx = undef; $query = "SELECT clmacidx FROM tblmac where clmac = ?"; if($debug == 1) { print "QUERY: \"$query\"\n"; } $sth = $dbh->prepare($query); $sth->execute($mac); $sth->bind_columns(undef, \$macidx); while(@row = $sth->fetchrow_array()) { $ect++; } $sth->finish; #### $macidx is now the value of "clmacidx" from select statement if($ect != 1) { print "UNK ECT: \"$ect\" FOR MAC: \"$mac\" L: \"" . __LINE__ . "\" NEXT\n"; } if(!(defined $macidx) || ($macidx eq "")) { print "MACIDX: \"$macidx\" IS UNDEF NEXT L: \"" . __LINE__ . "\"\n"; } if($debug == 1) { print "MACIDX: \"$macidx\" L: \"" . __LINE__ . "\"\n"; } #### $query = undef; $sth = undef; $ect = 0; @row = (); $dbok = 1; $query = "SELECT cllseen, clmacidx FROM tblmac where clmac = ?"; if($debug == 1) { print "QUERY: \"$query\"\n"; } $sth = undef; $sth = $dbh->prepare($query); $sth->execute($mac); my $mts = undef; $macidx = undef; $sth->bind_columns(undef, \$mts, \$macidx); while(@row = $sth->fetchrow_array()) { $ect++; } $sth->finish; if($debug == 1) { print "ECT: \"$ect\"\n"; } if($ect == 0) { if($debug == 1) { print "MAC: \"$mac\" DOES -NOT- EXIST. INSERTING L: \"" . __LINE__ . "\"\n"; } ### DB $query = undef; $sth = undef; $query = "INSERT INTO \`tblmac\` (clits, clts, clmac, clupby, cllseen) values (?,?,?,?,?)"; if($debug == 1) { print "QUERY: \"$query\"\n"; } eval { $sth = $dbh->prepare($query); $sth->execute($ineptime,$ineptime,$mac,$val,$ineptime); 1; } or do { print "$dtime CANT CONNECT TO SERVER L: \"" . __LINE__ . "\" SLEEPING 30\n"; sleep 30; return($dbh); }; $sth->finish; ### EO DB }