Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to monitor my linux logs and pull information from the logs to process the files that activities of the workers I do, in my company.

#!/bin/bash

#if [[ -z "$1" ]]; then
#       echo "Error: usage: autoParseMD5EncZip [device_id]"
#else
        yearCalc=`perl -e 'use Date::Calc qw(Today Add_Delta_Days); my ($y)=Add_Delta_Days(Today(), -1); print "$y"'`
        monthCalc=`perl -e 'use Date::Calc qw(Today Add_Delta_Days); my ($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); my ($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); my ($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 to parse logs linux today. In the day time it is also using the above script. I will found this 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 the problem is perl time, if i'm parse linux log today (07/10/2013). After I run my script. I found it that problem. Because my script just parser log linux file yesterday ([today-1]/10/2013). I try to parse log yesterday in this day and its work.

my problem is to change perl time, in order to parse the log linux file today.

Anyone please help me. Because I do not have basic in perl programming. Thanks for read it... :)

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.