The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 07-02-2009
koma koma is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 3
is not that simple if the date does not appear in the file because in that minute/hour doesn't log ?

---------- Post updated at 06:16 AM ---------- Previous update was at 05:43 AM ----------

Done
Code:
#!/usr/local/bin/bash
export PATH="$PATH:/usr/local/coreutils/bin"
#07/02/09 12:35:57
ADESSO=$(cdate "+%m/%d/%y %H:%M")
UNORAFA=$(cdate -d "1 hour ago" "+%m/%d/%y %H:%M")
UNORAFA_S=$(cdate -d "1 hour ago" +%s)
echo $ADESSO
echo $UNORAFA
echo $UNORAFA_S
A="0"
while [ "$A" -lt "61" ] ; do
        echo $A
        QUACK=$(grep -n "$UNORAFA" daemon.log|tail -1)
        if [ "$QUACK" = "" ]; then
                let A=$A+1
                let UNORAFA_S=$UNORAFA_S+60
                UNORAFA=$(cdate -d "@$UNORAFA_S" "+%m/%d/%y %H:%M")
                echo devo provare $UNORAFA
        else
                echo TROVATO $UNORAFA
                echo $QUACK
                TOTAIL=$(echo $QUACK |awk -F\: '{print $1}')
                NUMLINES=$(wc -l daemon.log|awk '{print $1}')
                echo $TOTAIL
                echo $NUMLINES
                let TOTAIL=$NUMLINES-$TOTAIL
                tail -$TOTAIL daemon.log > ESTRATTO.txt
                A=61
        fi
done