Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Location
    ZA
    Posts
    24

    Angry Unanswered: Newbie in the deep end

    Being a newbie ( unix is sooo cool ) my knowledge is not all that great. So i seek help. I need too automate the backup of log files. The problem comes in that log too be backed up is the day before. I thought this would be easy.

    __________________________________________________ _________
    day=x
    date +%d > date.log
    for dy in $(seq -w 31)
    do
    if grep $dy date.log
    then day=$(expr $dy - 1) ;
    fi
    done
    #
    #
    month=x
    date +%B > month.log
    for mnth in January February March April May June July August September October November December
    do
    if grep $mnth month.log
    then month=$mnth ;
    fi
    done
    #
    #
    year=x
    date +%Y > year.log
    for yr in 2000 2001 2002 2003 2004 2005
    do
    if grep $yr year.log
    then year=$yr ;
    fi
    done
    __________________________________________________ _________

    Ok, it looks messy but i at least thougt it did the job.
    Here's the prob : -
    Line 6) then day=$(expr $dy - 1) ;
    When $dy=1 , 1 - 1 =0 . Last time i checked the calendar there was no 0 of the month .

    In a nutshell i somehow need too calculate the current date less 1 day. Can this be done or do i have too turn too another scripting language.
    HELP!!

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Have a look at the command 'find'. The mtime option can be used to list files that have been modified within a specified number of 24 hour periods.

    e.g.

    find . -mtime 1

    find . -mtime +1 (inverts the above)

    HTH

  3. #3
    Join Date
    Sep 2003
    Location
    ZA
    Posts
    24

    Wink

    Thanx for the nfo Damian. Problem is that find is gonna pull all files updated within last 24 hours. I need too somehow get 01-03-2003 too 28-02-2003 . So there is going too have too be some form of intelligence in it.

  4. #4
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Originally posted by mccrack_2003
    Thanx for the nfo Damian. Problem is that find is gonna pull all files updated within last 24 hours. I need too somehow get 01-03-2003 too 28-02-2003 . So there is going too have too be some form of intelligence in it.
    You could use find with the -newer flag

    First create a file with a timestamp to use as the cutoff point...

    touch -t 200309181230.00 timeCutOffFile

    find timeCutOffFile -newer yourLogFile

    The above would return "timeCutOffFile" if it is newer than yourLogFile, hence...

    if ! test -z "$(find timeCutOffFile -newer yourLogFile)"
    then
    # if the result of the find is not empty, yourLogFile must be older
    doStuffWithYourLogFile
    fi

    You can stick some more logic round that and you should have what you want.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •