請問如何將此shell script 改寫為perl - Perl, CGI - 程式設計 - 頂客論壇 ,免費遊戲,免費交友,免費空間,免費部落格,免費相簿,免費開店 - 頂客社區 dk101.com 最用心的華人社群網站
發新話題

[問題] 請問如何將此shell script 改寫為perl

請問如何將此shell script 改寫為perl

#!/bin/bash
#set -x
fileday=$1
result_file=Total`date +%Y%m%d%H%M`
out_folder=/home/cmd/pm_analyze
tmp_folder=/tmp/pmtmp
datatype='split licenceCounter cdrsReceivedTotSum cdrsCombinedSum cdrsAggregatedSum'
ch_server() {
###### Choosing which server #################
echo "Please Choose Host IP  ?"
echo " 1) CGX02 172.17.11.23"
echo " 2) CGX03 172.17.11.24"
echo " 3) CGW03 172.17.12.23"
echo " 4) CGW04 172.17.12.24"
echo " 5) CGT01 172.17.9.51"
read server
if [ "$server" = "1" ]
then
hostip="172.17.11.23"
elif [ "$server" = "2" ]
then
hostip="172.17.11.24"
elif [ "$server" = "3" ]
then
hostip="172.17.12.23"
elif [ "$server" = "4" ]
then
hostip="172.17.12.24"
else
hostip="172.17.9.51"
fi
}
proc_pm() {
for i in $datatype
do
total=0
number=0
filename=$tmp_folder/$i.log
echo "Now processing $filename"
while read line
do
  number=` echo $line |  cut -d '>' -f2 | cut -d '<' -f1 `
  let total+=number
done < $filename
echo " the $i total sum = $total" >> $out_folder/$result_file
done
}
#### Check Output folder exit or not #################
if [ ! -d $out_folder ]
then
echo "#######output folder not exit !! Creating #####"
mkdir -p $out_folder
if [ ! -d $out_folder ]
  then
  echo "Creating Fail !! Pleae check"
  exit
ele
  echo "Create Succes"
fi
fi
if [ ! -d $tmp_folder ]
then
echo "#######TMP folder not exit !! Creating #####"
mkdir -p $tmp_folder
if [ ! -d $tmp_folder ]
  then
  echo "Creating Fail !! Pleae check"
  exit
ele
  echo "Create Succes"
fi
fi
##################Checking tmp folder data ##################
echo "************************ Warring **************************"
echo "*** All the files under temp folder will be deleted. ******"
echo "*** Temp folder is $tmp_folder         ******"
echo "***********************************************************"
read -p "Are you sure continue processing (yes/no):" answer
#read answer
if [ "$answer" == "n" ] || [ "$answer" == "no" ]
then
exit 0;
else
tmpfiles=`ls -al $tmp_folder/*.log | wc -l`
if [ "$tmpfiles" == "0" ]
then
  echo "***************************************************************"
  echo " ********* OK, There are no any logs under $tmp_folder ********"
  echo "***************************************************************"
else
  rm $tmp_folder/*
  tmpfiles1=`ls -al $tmp_folder/*.log | wc -l`
  echo $tmpfiles1
  if [ "tmpfiles1" == "0" ]
  then
   echo " ********* OK, All files are deleted ********"
  else
   echo " ********* There are some logs cannot deleted. Please check it. ********"
   exit 0
  fi
fi
  
fi
##### choosing which file type #################
echo "Please Choose Solution  ?"
echo " 1) Please Input An filename ?"
echo " 2) Summation Daily Total Counts"
read ftype

if [ "$ftype" == "1" ]
then
echo "Please input filename and file path"
read filepath
if [ ! -e "$filepath" ]
then
  echo "************************************"
  echo "*****Shit!! File does not exist****"
  echo "************************************"
  exit
fi
for i in $datatype
do
         gzcat $filepath |grep $i  >> $tmp_folder/$i.log
done
proc_pm;
elif [ $ftype == "2" ]
then
echo " Please input date for processing "
read filedate
ch_server;
echo "Please input path "
read datepath
datefile=`ls -al $datepath/PM.$hostip.$filedate.*.xml.gz | wc -l`
if [ "$datefile" == "0" ]
then
  echo "Sorry !! There are no PM files under $datepath"
  exit 1
fi
for i in $datatype
do
  gzcat $datepath/PM.$hostip.$filedate.*.xml.gz |grep $i  >> $tmp_folder/$i.log
done
proc_pm;
else
echo "Sorry!! You don't give me the right command"
fi

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。