Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    Unanswered: file exist in folder.

    Hi guys,

    i am new to shell scripting and want to write one script, the details is like

    i want to check the file in particular folder, if that file is exists in folder more than three hours then send a message.

    so please help me.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    How frequently do you want to run this script?

    Create a marker file, and use "touch" to change its date and time modified.
    Then use "ls -tr" to list the files in chronological order, oldest first.
    Code:
    touch marker.lck
    sleep 10800   #3 hours * 60 minutes * 60 seconds
    ls -tr >list 
    while read a
    do
       if [ $a = "marker.lck" ]
         then
          exit
       else
         echo $a "older than three hours"
        fi
    done <list

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    Thanks Kite.

    I want to do filename as parameter, so how i can call filename as parameter.

    i need to check two files in that directory, for that i can write a code for two files.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Which operating system are you using? There are various versions of the "date" command, some do date arithmetic others don't.
    For example "Mar 1 2012 01:30" minus 3 hours is "Feb 29 2012 22:30".

    Are you only interested in any three hours between 6am and 9 pm?

    This link has lots of information Yesterdays Date/Date Arithmetic - The UNIX and Linux Forums

Posting Permissions

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