perl - Can't Parsing Log Linux File Today -
i'd monitor linux logs , pull information logs process files activities of workers do, in company.
#!/bin/bash #if [[ -z "$1" ]]; # echo "error: usage: autoparsemd5enczip [device_id]" #else yearcalc=`perl -e 'use date::calc qw(today add_delta_days); ($y)=add_delta_days(today(), -1); print "$y"'` monthcalc=`perl -e 'use date::calc qw(today add_delta_days); ($y,$m)=add_delta_days(today(), -1); if ($m<=9) {$m = "0".$m;} print "$m"'` prefixcalc=`perl -e 'use date::calc qw(today add_delta_days); ($y, $m, $d)=add_delta_days(today(), -1); if ($m<=9) {$m = "0".$m;} if ($d<=9) {$d = "0".$d;} print "$y$m$d"'` secaudit=`perl -e 'use date::calc qw(today add_delta_days); ($y, $m, $d)=add_delta_days(today(), -1); if ($m<=9) {$m = "0".$m;} if ($d<=9) {$d = "0".$d;} print "$d-$m-$y"'` pathsource="/syslog" pathdest="/syslog3/secaudit" #echo "ls -als /syslog/$yearcalc/$monthcalc/$prefixcalc-$1.gz"i nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] parsing gw1 ..." logparser.app $pathsource/$yearcalc/$monthcalc/$prefixcalc-gw1 $pathdest/idmob-$secaudit.csv nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] parsing gw2 ..." logparser.app $pathsource/$yearcalc/$monthcalc/$prefixcalc-gw2 $pathdest/idmob-$secaudit.csv nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] encrypt gpg" gpg --batch -e -r indomobile --keyring /root/.gnupg/pubring.gpg -o $pathdest/idmob-$secaudit.csv.gpg $pathdest/idmob-$secaudit.csv nowtgl=$(date +%d/%m/%y\ %h:%m:%s) #rm -f $pathdest/idmob-$secaudit.csv nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] bzip-ing ..." bzip2 $pathdest/idmob-$secaudit.csv.gpg nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] md5sum-ing ..." md5sum $pathdest/idmob-$secaudit.csv.gpg.bz2 > $pathdest/idmob-$secaudit.md5 nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] gzip-ing gw1 ..." gzip /syslog/$yearcalc/$monthcalc/$prefixcalc-gw1 nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] gzip-ing gw2 ..." gzip /syslog/$yearcalc/$monthcalc/$prefixcalc-gw2 nowtgl=$(date +%d/%m/%y\ %h:%m:%s) echo "[$nowtgl] finish" echo " " echo "----------------------------------" echo " " echo " " #fi
if i'm going parse logs linux today. in day time using above script. found problem :
bzip2: can't open input file /syslog3/secaudit/idmob-06-10-2013.csv.gpg: no such file or directory. [07/10/2013 09:43:07] md5sum-ing ...
md5sum: /syslog3/secaudit/idmob-06-10-2013.csv.gpg.bz2: no such file or directory [07/10/2013 09:43:07] gzip-ing gw1 ...
gzip: /syslog3/2013/10/20131006-gw1: no such file or directory [07/10/2013 09:43:07] gzip-ing gw2 ...
gzip: /syslog3/2013/10/20131006-gw2: no such file or directory [07/10/2013 09:43:07] finish
i know problem perl time, if i'm parse linux log today (07/10/2013). after run script. found problem. because script parser log linux file yesterday ([today-1]/10/2013). try parse log yesterday in day , work.
my problem change perl time, in order parse log linux file today.
anyone please me. because not have basic in perl programming. read it... :)
your perl scripts have add_delta_days(today(), -1)
, takes today's date , subtracts 1 day, resulting in yesterday. if want use today's date instead, can change today()
.
Comments
Post a Comment