#!/usr/bin/perl -w use strict; use File::Basename; use XML::Simple; package CITIC; my $TPMS_EOD_ETC=$ENV{TPMS_EOD_ETC}; #return script name sub getscript_name{ my($path)[email protected]_; my $script_name=File::Basename::basename($path); #( my $pgm = $0 ) =~ s!.*\\(.*)!$1!g ; $script_name =~ s/.pl$|.sql$//; return $script_name; } #return dbh; sub connect_db{ my ($ip,$port,$sid,$user,$pwd)[email protected]_; #CITIC::showtime();print "$ip,$port,$sid,$user,$pwd"."\n"; my $dbh; eval{ $dbh = DBI->connect("DBI:Oracle:host=$ip;port=$port;sid=$sid", $user,$pwd,{AutoCommit=>1,PrintError=>1,RaiseError=>0}); }; #or die "Can‘t connect db,DBI->errstr"; unless ($dbh){ CITIC::showtime();print DBI->errstr."\n"; }else{ CITIC::showtime();print "Connect db success!"."\n"; } return $dbh; } #return dbc info sub get_dbc_info{ my ($subdbc)[email protected]_; my $dbc_file="dbc.xml"; my $xmlfile = "${TPMS_EOD_ETC}${dbc_file}"; my $xml = XML::Simple->new(); my $info = eval{$xml->XMLin($xmlfile,ForceArray => 1)}; my $CONFIGINFO=$info; my %dbc_info; foreach my $get_info(keys(%{$CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}})){ $dbc_info{"user"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"user"}; $dbc_info{"pwd"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"pwd"}; $dbc_info{"ip"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"ip"}; $dbc_info{"port"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"port"}; $dbc_info{"sid"} = $CONFIGINFO->{"config"}->{"$subdbc"}->{"info"}->{"$get_info"}->{"sid"}; } return %dbc_info; } #去除空格 sub strimstr{ my $str=shift; s/^\s+//; s/\s+$//; return $str; } #return hh:mm:ss yyyymmdd sub showtime{ my($sec,$min,$hour,$day,$mon,$year)=localtime(time()); my $current=""; $sec=sprintf("%02d",$sec); $min=sprintf("%02d",$min); $hour=sprintf("%02d",$hour); $day=sprintf("%02d",$day); $mon=sprintf("%02d",$mon+1); $year+=1900; $current="$hour".":$min".":$sec"." $year"."$mon"."$day"; print "${current} INFO : "; } #return yyyymmdd sub getdate{ my($sec,$min,$hour,$day,$mon,$year)=localtime(time()); my $current=""; $sec=sprintf("%02d",$sec); $min=sprintf("%02d",$min); $hour=sprintf("%02d",$hour); $day=sprintf("%02d",$day); $mon=sprintf("%02d",$mon+1); $year+=1900; $current="$year"."$mon"."$day"; return "${current}"; } #return openfile sub create_logfile($$){ my ($filename,$path)[email protected]_; my $get_date=getdate(); my $get_time=localtime(time()); open(FILE,">","${path}${filename}_${get_date}.log") or die "Can`t Create file :$!"; print FILE "-" x 8 ."[$get_time] Start"."-" x 8 . "\n"; return *FILE; } #close open; sub close_logfile($){ my ($log_file)[email protected]_; my $get_time=localtime(time()); print $log_file "-" x 8 ."[$get_time] End"."-" x 8 . "\n"; close($log_file); } #return true; 1;
时间: 2024-11-09 05:13:24