📄 stdcollect.pm
字号:
if ($r_match =~ /$exception/) { my $repre_errmode=$connect_hdl->errmode($r_handle_MMICmd_error); $err_msg=''; my ($r_cmd_result_msg_tmp,$r_match_tmp)=$connect_hdl->waitfor(Match=>"/$expect/",Timeout=>$time_out); $connect_hdl->errmode($repre_errmode); print "$r_cmd_result_msg_tmp","$r_match_tmp\n"; print "------------------ retry $retry -------------------\n"; } if(!$err_msg and ($r_match=~/$expect/) and ($r_match !~/$exception/)) { print "collect successfully\n"; print "---------------------about waitfor-----------------\n"; return (1,$r_cmd_result_msg.$r_match); } $retry -=1; } } } } print "collect failed \n"; print "---------------------about waitfor-----------------\n"; return (-1,$cmd_result_msg.$match); } print "\ncollect successfully\n"; print "---------------------about waitfor-----------------\n"; return (1,$cmd_result_msg.$match);}################################################################ Function:col_ftp## Input::a ref of a hash which contains information for rsh.This# hash has following structure:# {# remotehost=>hostname,# username=>username,# password=>password,# localfile=>localfile,# remotefile=>remotefile# action=>put or get# timer=>timeout # }# ## Output:## Return value:## Description:###############################################################sub col_ftp{ my $pkg=shift; my $ftp_inf=shift; my $r_current_errinf=shift; my $error_tag=shift; my $share_handle=shift; my $error_hdl = $pkg->{'ErrMessage_hdl'}; my $remotehost=$ftp_inf->{'remotehost'}; my $usr=$ftp_inf->{'username'}; my $passwd=$ftp_inf->{'password'}; my $localfile=$ftp_inf->{'localfile'}; my $remotefile=$ftp_inf->{'remotefile'}; my $act=$ftp_inf->{'action'}; my $timeout=$ftp_inf->{'timer'}; my $share_tag=$ftp_inf->{'share_handle'}; my $ftp; if ((ref($share_handle) eq "Net::FTP") and $share_tag) { $ftp = $share_handle; } else { $ftp=Net::FTP->new("$remotehost", Debug => 0,Timeout=>$timeout); if(!($ftp->login("$usr","$passwd"))){ if ($error_hdl) { my $log_info = "ftp login $remotehost failed: user=$usr,password=$passwd"; my $re_code = $pkg->write_dallog($log_info,$remotefile,'2110'); if ($re_code<0) { DBIs::Trace("Can't Write dal_log\n"); } } my $err_msg="ftp $remotehost failed: user=$usr,password=$passwd \n"."\t File:".__FILE__."\t Line:".__LINE__."\n"; DBIs::Trace("$err_msg",1,1030206,$pkg->{'task_id'}); return (-1,$err_msg); } $ftp->binary(); DBIs::Trace("Translate Type: Binary \n"); } if($act eq "get"){ my $getfile=$ftp->get($remotefile,$localfile); if($getfile eq $localfile){ #$ftp->close(); DBIs::Trace("get $remotefile success \n"); return (1,"get $remotefile success \n",$ftp); } else{ DBIs::Trace("get $remotefile fail \n"); if ($error_hdl) { my $log_info = "ftp $remotehost get file: $remotefile fail! user=$usr,password=$passwd"; my $re_code = $pkg->write_dallog($log_info,$remotefile,'2107'); if ($re_code<0) { DBIs::Trace("Can't Write dal_log\n"); } } my $err_msg="get $remotefile fail \n"."\t File:".__FILE__."\t Line:".__LINE__."\n"; DBIs::Trace("$err_msg",1,1030207,$pkg->{'task_id'}); $ftp->close(); return (-2,$err_msg); } } if($act eq "put"){ my $putfile=$ftp->put($localfile,$remotefile); if($putfile eq $remotefile){ DBIs::Trace("put $localfile success \n"); #$ftp->close(); return (1,"put $localfile success \n",$ftp); } else{ DBIs::Trace("put $localfile fail \n"); if ($error_hdl) { my $log_info = "ftp $remotehost put file: $localfile fail! user=$usr,password=$passwd"; my $re_code = $pkg->write_dallog($log_info,$remotefile,'2108'); if ($re_code<0) { DBIs::Trace("Can't send Warning Message\n",1); } } $ftp->close(); my $err_msg="put $localfile fail \n"."\t File:".__FILE__."\t Line:".__LINE__."\n"; DBIs::Trace("$err_msg",1,1030208,$pkg->{'task_id'}); return (-1,$err_msg); } } if($act eq "mget"){ my ($return_val,$msg,$handle)= mget($ftp,$ftp_inf,$error_hdl); #$ftp->close(); return ($return_val,$msg,$handle); }}################################################################# Function:mget## Input:### Return value:## Description:#################################################################sub mget { my ($ftp,$input,$error_hdl) = @_ ; my $remotehost=$input->{'remotehost'}; my $usr=$input->{'username'}; my $passwd=$input->{'password'}; my $remotepath=$input->{'remotepath'}; my $remotefile=$input->{'remotefile'}; my $localpath=$input->{'localpath'}; if ($localpath !~ /\/$/) { $localpath .= "/"; } my $tmp_localfile=$input->{'localfile'}; $tmp_localfile = $localpath.$tmp_localfile; my $time_out=$input->{'timer'}; $ftp->cwd($remotepath); $file_list=$ftp->ls; foreach $file (@$file_list) { my $localfile = $tmp_localfile.$file; if ($file=~/$remotefile/){ my $getfile=$ftp->get($file,$localfile); if($getfile ne $localfile) { my $log_info = "ftp $remotehost get file: $file fail! user=$usr,password=$passwd"; DBIs::Trace("$log_info\n"); if ($error_hdl) { my $re_code = $pkg->write_dallog($log_info,$remotefile,'2107'); if ($re_code<0) { DBIs::Trace("Can't send Warning Message\n",1); } } } else { DBIs::Trace("file:$file get successfully!\n"); } } } return (1,"mget successfully!",$ftp);}################################################################# Function: col_syscmd## Input:### Return value:## Description:#################################################################sub col_syscmd { my ($pkg,$input_ref,$err_inf,$err_tag) = @_; my $sys_cmd = $input_ref->{'cmdline'}; my $Flow_tag = $input_ref->{'Flow_tag'}; #print "System CMD: $sys_cmd \n\n"; DBIs::Trace("System CMD: $sys_cmd \n\n"); my $return_code = system($sys_cmd); if ($return_code ==0) { return (1,"System CMD: $sys_cmd Successfully\n"); }else { return (-1,"CMD: $sys_cmd failed !!! \n"); }}############################################################################### Function: trans_string2hex## Input: string## Output:## Return value:hexstring## Description:Control marks will be escaped when they are written in xml file.# This function will resume that translation.###############################################################################sub trans_string2hex{ my $string=shift; #print "--- $string--\n"; my @elements=split /\\x/,$string; my $hexstring; shift(@elements); foreach $element (@elements){ if(defined $element){ my $trans1_element=hex($element); my $trans2_element=pack "c*", $trans1_element; # print "trans2 is $trans2_element \n"; $hexstring=$hexstring.$trans2_element; } } return $hexstring;}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -