Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    54

    Question Unanswered: Monitor a directory for a file

    I have a file system called /datafiles. Within this file system I allow remote users to upload files to me with the structure of "upload.0002", "upload.0003", "upload.0004", etc. I want to monitor this directory with a Korn script running at certain times via crontab, that will identify when one of these files exist then run a series of commands on the file that is found. I need to:

    1) Be able to identify the file when it is present and has been completely uploaded

    2) Discover the files extension (i.e. 0002, 0003, 0004, etc.)

    3) Run a series of commands of the file using its extension as an argument.

  2. #2
    Join Date
    May 2003
    Location
    France
    Posts
    112

    Re: Monitor a directory for a file

    hi,

    find your_dir -name 'upload*' |wc -l gives you number of upload file in your directory

    ls -l your_dir | awk '{ FS="." ;print $2 }' gives you file extension.

    hope this help you

    Originally posted by heprox
    I have a file system called /datafiles. Within this file system I allow remote users to upload files to me with the structure of "upload.0002", "upload.0003", "upload.0004", etc. I want to monitor this directory with a Korn script running at certain times via crontab, that will identify when one of these files exist then run a series of commands on the file that is found. I need to:

    1) Be able to identify the file when it is present and has been completely uploaded

    2) Discover the files extension (i.e. 0002, 0003, 0004, etc.)

    3) Run a series of commands of the file using its extension as an argument.

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    The following (untested) code tests if a file has updated in the last 60 seconds. If it hasn't, assume it is completely uploaded and process it.

    HTH

    processFile ()
    {
    local fileName=$1
    local fileExtension=$2
    # doStuffWithFile
    }

    # Main Processing

    for fileName in uploadDirectory/upload.[0-9][0-9][0-9][0-9]
    do
    fileExtension=${fileName#*.}
    fileTest=/tmp/$fileName.$(date +%d%m%y_%H%M%S)
    cp -f $fileName $fileTest
    sleep 60
    test "$fileName" != "$(find $fileName -newer $fileTest)" > /dev/null && processFile fileName fileExtension
    done

Posting Permissions

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