Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: Check files for yesterday's date

    Suppose I have a directory /home/sac where I have a file xxx.dat

    How can I write a script that I would like to schedule in cron where it should just check if xxx.dat is yesterday's file. If so, it should write a message to a log file saying "Latest xxx.dat file exists".
    If the file does not have yesterday's date, it should write a message to the log file saying "Latest xxx.dat file does not exist".


    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81
    MY_MONTH=`date -d'1 day ago' +%b`
    MY_DAY=`date -d'1 day ago' +%d`
    ls -ltr|awk -v my_month=$MY_MONTH my_day=$MY_DAY '{if(my_month==$6 && my_day==$7) {print $9 "\t is yesterdays file}else{print $9 "\t is yesterdays file"}}'

    I hope it helps you

  3. #3
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi,
    where you can see the time stamp ?
    Is it the last create or modify date in ls -l command ?
    then please give me an example from the output your "ls -l xxx.dat"

    or have the file a time stamp in the filename ?
    then please give me an example from the filename.

    I think we find a solution for your problem
    Greetings from germany
    Peter F.

  4. #4
    Join Date
    Feb 2004
    Posts
    143
    Hi ducasio,

    So if that is the case, to find if xxx.dat is yesterday's file, can I just say

    MY_MONTH=`date -d'1 day ago' +%b`
    MY_DAY=`date -d'1 day ago' +%d`
    ls -ltr xxx.dat |awk -v my_month=$MY_MONTH my_day=$MY_DAY '{if(my_month==$6 && my_day==$7) {print $9 "\t xxx.dat is yesterdays file}else{print $9 "\t xxx.dat is not yesterdays file"}}'

    Or is there something more to it ?

    Thanks

  5. #5
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    ..... assuming GNU's "date"
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  6. #6
    Join Date
    Feb 2004
    Posts
    143
    Vlad,
    What is GNU's date ???

  7. #7
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    " -d'1 day ago' " is GNU's date switch not generally available [for example Solaris stock 'date']
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  8. #8
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi saccskiz ,

    do you have get a solution for your problem ?
    Greetings from germany
    Peter F.

Posting Permissions

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