⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdcollect.pm

📁 Perl开发的数据采集工具 基于UNIX
💻 PM
📖 第 1 页 / 共 2 页
字号:
package StdCollect;#################################################################################  @(#) Perl Module: StdCollect##  Copyright(C) 2002-2004 BOCO Inter-Telecom DC Team, All Rights Reserved##  Author(s): JiaXiaoLong#  #  Creation Date: 2002/12/23##  Last update Date: 2003/02/27##  Description:################################################################################use Net::Telnet();use Net::FTP;use Exporter;use Data::Dumper;@ISA=('Exporter');@EXPORT=qw(col_ftp col_MMI col_MMICmd col_syscmd);local $err_msg;$r_handle_rcp_error=sub {	$err_msg=shift;	print "It is in handle_rcp_error now. \n";	return $err_msg;};$r_handle_rsh_error=sub {	$err_msg=shift;	print "It is in handle_rsh_error now. \n";	return $err_msg;};$r_handle_MMICmd_error=sub {	$err_msg=shift;	print "It is in handle_MMICmd_error now. \n";	return $err_msg;};################################################################  Function:col_MMI##  Input:#  Output:##  Return value:##  Description:##############################################################sub col_MMI{	my $pkg=shift;	my $r_MMI_inf=shift;	my $r_ERR_inf=shift;	my $error_tag = shift;	my ($return_code,$return_msg);	#-------------------------------------------------	# if we don't care the result,the resultfile 	# should be /dev/null in config file.Important!	#-------------------------------------------------	my $result_file=$r_MMI_inf->{'resultfile'};	#-----------------------------------------	# execute MMI Command	#-----------------------------------------	my $connect_handle=$pkg->{'connect_handle'};	DBIs::Trace("Connect handle is $connect_handle\n");	($return_code,$return_msg)=$pkg->col_MMICmd($connect_handle,$r_MMI_inf,$r_ERR_inf,$error_tag);	#----------------------------------------	# success. print result into $result_file	#----------------------------------------	if ($return_code==1){		if(!open(RST,">>$result_file")){			my $err_msg="Can't open $result_file.\n File:".__FILE__."\tLine:".__LINE__."\n";			DBIs::Trace("Can't open $result_file\n",1,1030205,$pkg->{'task_id'});			return (-1,$err_msg);}		print RST $return_msg;		close(RST);	}	#------------------------------------------	# need more code here for handling $return_msg	# need trace here.	#------------------------------------------	return ($return_code,$return_msg);}################################################################  Function:col_MMICmd##  Input:#       1. the handle of connection (telnet or socket)#       2. a ref of a hash which contains information for MMICmd.#           This hash has following structure:#         {#               cmdline=>command line,#               expect=>expect mark,#      ##  Input: #	1. the handle of connection (telnet or socket)#	2. a ref of a hash which contains information for MMICmd.#	    This hash has following structure:#	  {#		cmdline=>command line,#		expect=>expect mark,#		except=>exception mark,#		prepare=>some command line need pre_processing.#		newline_mark=>the mark of a new line#		timer=>timeout#	  }##  Output:##  Return value:success (1,result msg)#		failure (-1,serious err msg)#		failure (-2,not serious err msg)#		failure (-10,msg of unknown err)##  Description:###############################################################sub col_MMICmd{	my $pkg=shift;	my $connect_hdl=shift;	my $r_command_inf=shift;	my $r_error_inf=shift;	my $error_tag=shift;	my $error_hdl = $pkg->{'ErrMessage_hdl'};	my $cmd_line=$r_command_inf->{'cmdline'};	my $expect=$r_command_inf->{'expect'};	my $exception=$r_command_inf->{'except'};	my $time_out=$r_command_inf->{'timer'};	#------------------------------------------	# $exception shouldn't be null,	# otherwise method 'waitfor' will get nothing back. 	#------------------------------------------	if((!$exception) and ($exception!~'0')){$exception='DEFAULT_ERROR';}	if((!$expect) or ($expect =~ /DEFAULT/i)){$expect="[\\\$%#>]\\s*\$";}		if (ref($connect_hdl) ne "Net::Telnet") {		my $err_msg="invalid connect_hdl\n File:".__FILE__."\t Line:".__LINE__."\n";		DBIs::Trace("$err_msg",1,1030205,$pkg->{'task_id'});		return (-1,$err_msg);	}	my $pre_errmode=$connect_hdl->errmode($r_handle_MMICmd_error);	$err_msg=''; 		sleep(1);	$connect_hdl->print($cmd_line);	print "---------------------about waitfor-----------------\n";	print "SEND: ",$cmd_line,"\n";	print "WAIT: $expect|$exception","\n";	print "TIME: $time_out \n";		my ($cmd_result_msg,$match)=$connect_hdl->waitfor(Match=>"/($expect|$exception)/",Timeout=>$time_out);	print $cmd_result_msg,"\n";	print $match;	#------------------------------------	# if there are $err_msg, then...	#------------------------------------	$connect_hdl->errmode($pre_errmode);	if(($err_msg=~/timed\-out/) and ($error_hdl)){		my $log_info = $err_msg." CMD: $cmd_line";		my $re_code= $pkg->write_dallog($log_info,$cmd_line,'2102');		if ($re_code<0) {			DBIs::Trace("Can't send Warning Message\n");		}		$err_msg="\n".$err_msg."\t File:".__FILE__."\t Line:".__LINE__."\n";		DBIs::Trace("$err_msg",1,1030205,$pkg->{'task_id'});		return (-1,$err_msg);	}	elsif (($err_msg) and ($error_hdl)){		my $log_info = $err_msg." CMD: $cmd_line";		my $re_code= $pkg->write_dallog($log_info,$cmd_line,'2199');		if ($re_code<0) {			DBIs::Trace("Can't send Warning Message\n");		}		$err_msg="\n".$err_msg."\t File:".__FILE__."\t Line:".__LINE__."\n";		DBIs::Trace("$err_msg",1,1030205,$pkg->{'task_id'});		return (-1,$err_msg);	}	elsif (($err_msg) and !($error_hdl)) {		$err_msg="\n".$err_msg."\t File:".__FILE__."\t Line:".__LINE__."\n";		DBIs::Trace("$err_msg",1,1030205,$pkg->{'task_id'});		return (-1,$err_msg);	}	#-----------------------------------------------------------------	# in this case, result_data like $exception (bad data we defined)	#-----------------------------------------------------------------	if ($match=~/$exception/) {		#--------------------------------------------------		# we must clear data_buffer in Telnet_hdl for next collection.		# and write dal_log before next collection.		#--------------------------------------------------		if ($error_hdl) {			my $log_info = "$exception CMD: $cmd_line";			my $re_code= $pkg->write_dallog($log_info,$cmd_line,'2199');			if ($re_code<0) {				DBIs::Trace("Can't send Warning Message\n");			}		}		my $pre_errmode=$connect_hdl->errmode($r_handle_MMICmd_error);		$err_msg='';		sleep(1);		my ($cmd_result_msg_tmp,$match_tmp)=$connect_hdl->waitfor(Match=>"/($expect)/",Timeout=>$time_out);		print "$cmd_result_msg_tmp","$match_tmp\n";		$connect_hdl->errmode($pre_errmode);		if($err_msg) {			$err_msg="\n".$err_msg."\t File:".__FILE__."\t Line:".__LINE__."\n";			DBIs::Trace("$err_msg",1,1030205,$pkg->{'task_id'});			return (-1,$err_msg);				}		#----------------------------------------------------------		# if there is $error_tag and $r_error_inf in col_cfg file,		# filecollector will collecting retry.		#----------------------------------------------------------		elsif (!$err_msg and $error_tag and ($error_tag !~ /NULL/i)) {			my @error_tag = split/,/,$error_tag;			foreach my $key (@error_tag) {				my $waittime = $r_error_inf->{$key}{'waittime'};				my $body = $r_error_inf->{$key}{'body'};				my $retry = $r_error_inf->{$key}{'retry'};				if ($match =~ /$body/) {					while($retry) {						#--------------------						# collect retry						#--------------------						my $pre_errmode=$connect_hdl->errmode($r_handle_MMICmd_error);   						$err_msg='';        					print "------------------ retry $retry -------------------\n";						print "Wait: $waittime \nBody: $body\nRetry:$retry\n";						print "Collecting Error: $body\n\n";						print "Waitfor $waittime ...\n";						sleep($waittime);						print "Now Retrying ... \n\n";						print "SEND: ",$cmd_line,"\n";        					print "WAIT: $expect|$exception","\n";        					print "TIME: ",$time_out,"\n";						$connect_hdl->print($cmd_line);        					my ($r_cmd_result_msg,$r_match)=$connect_hdl->waitfor(Match=>"/($expect|$exception)/",Timeout=>$time_out);        					print $r_cmd_result_msg,$r_match;        					$connect_hdl->errmode($pre_errmode);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -