1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

if file exist and has mod date of... (unix).

Discussion in 'Linux and Unix' started by cgjoker, Mar 9, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I am working on a different approach using the date command.

    date --date='1 day ago'
     
  2. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    sorry.... didn't realize there was a page two and i thought you guys might have thought this was closed.

    thanks.

    any luck so far?

    i tried this and it somewhat works but i noticed that the file is returned as

    ./1file1.dat rather than 1file1.dat so therefore it is not getting copied.

    for file in `find ./ -type f -mtime +1 `
    do
    if [ -f $file ]
    then
    case $file in
    1*.*)
    cp $file /mdm_work/Campaign_Downloads/test
    echo "$file copied" >> /test/processing.log
    ;;
    *)
    echo "$file: appears to be other" >> /test/processing.log
    ;;
    esac
    fi
    done
     
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    This should do it.

    Code:
    date1=`date +%Y-%m-%d -d "yesterday"`
    for filename in `find "/home/jfriberg/test" -type f -name "1*.*"`
    do
    grep1=`ls --full-time $filename | grep -c $date1`
    if [ $grep1 = "1" ]; then
    cp -p $filename /home/jfriberg/backup/
    fi
    done
     
  4. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    didn't work... i got the following error

    iw113:user:/test]./find_mod.sh
    date: 0551-402 Invalid character in date/time specification.
    Usage: date [-u] [+"Field Descriptors"]
    find: 0652-010 The starting directory is not valid.
     
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Works fine on my box. Post back the exact script you used and I will replicate the paths on my box. (Copy and Paste it!)

    Which version of Linux\Unix\BSD are you running this on?
    Which Shell are you using?
     
  6. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    if i copy and paste, as per below:

    date1=`date +%Y-%m-%d -d "yesterday"`
    for filename in `find "/EBCC" -type f -name "2*.*"`
    do
    grep1=`ls --full-time $filename | grep -c $date1`
    if [ $grep1 = "1" ]; then
    cp -p $filename /test/
    fi
    done

    I get the following error:

    iw113:cgalindo:/affinium/Campaign/Std_recur2_Validation/script]./mod.sh
    date: 0551-402 Invalid character in date/time specification.
    Usage: date [-u] [+"Field Descriptors"]
    ls: Not a recognized flag: -
    ls: Not a recognized flag: -
    Usage: ls [-1ACFLNRabcdefgilmnopqrstux] [File...]
    Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
    [-f pattern_file...] [file...]
    Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
    -f pattern_file... [file...]
    Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
    ./mod.sh[17]: test: 0403-004 Specify a parameter with this command.


    I should have mentioned we are actually on AIX 5.1.
     
  7. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    And what shell are you using. Scripts are dependent on what shell you are using. If you can install bash on their it should run. But you then need to put the interpreter at the top of the script.

    #!/bin/bash ( or wherever bash is installed on your system.)

    We probably shouldn't even really use test as a directory name because it is an acutal command. You might have to put the $Date1 variable in quotes.

    You might have to look at the manual pages for your shell environment to figure out how to get the full-time in the LS command and figure out how to get yesterday's date to output with those variables. I dont know what shell you are using so it is hard to say. If you have bash installed this script will run.
     
  8. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    sorry,... korne shell. I should have known that is what you were asking for.

    i dont think we have bash installed.

    this is the error if in quotes:

    iw113:user:/test]./mod.sh
    date: 0551-402 Invalid character in date/time specification.
    Usage: date [-u] [+"Field Descriptors"]
    ls: Not a recognized flag: -
    ls: Not a recognized flag: -
    Usage: ls [-1ACFLNRabcdefgilmnopqrstux] [File...]
    iw113:user:/test]
     
  9. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Do you think you could check. Try just typing bash at a shell prompt. If it is installed you will switch to a bash shell. If it is installed put this line at the top of your script.

    #!/bin/bash (or wherever bash is installed)

    Or do a find for it.
     
  10. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I just checked IBM's website. You can run bash on AIX. I dont have Korn installed on my box at home so I cannot test anything right now. I can loaded it up later tonight if I have time but I usually dont go on my computers during the weekend.
     
  11. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
  12. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    I think I have it installed already because I do recall running a bash script I created a long time ago. I guess I can just try a simple script to see if it works.

    I still don't know why though the reason id get these errors.. if you tried it with bash and I had it installed, it should run then shouldn't it?
     
  13. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Because your default shell is Korn and you dont have the interpreter defined at the top of the script. You have to put this at the top of the script.

    #!/path/to/bash (replace the path to bash with where it is on your system)
     
  14. cgjoker

    cgjoker Thread Starter

    Joined:
    Aug 13, 2003
    Messages:
    205
    Ill try this out. Thanks so much for all your time in trying to help me figure this out.
     
  15. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/339068