Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2004
    Posts
    37

    Unanswered: Verify File Arrival

    I have to verify the files, that I need to process have arrived on a certain directory. I have the file names in the variables.

    Directory where the file will arrive /home/dba/
    and the DATA_FILENAME = SOMETHING.dat
    SUMM_FILENAME=SOMETHING.sum

    Any help is appreciated.

  2. #2
    Join Date
    Feb 2004
    Posts
    5
    This is really easy:
    if [ -e $VAR_WITH_NAME ]; then
    echo File $VAR_WITH_NAME arrived
    fi

    --
    These emails are spam traps (though I read them)
    kaede.news@online.ru
    akrosum@yahoo.com

  3. #3
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Testing file existance isn't sufficient, the file transfert may be incomplete.

    The following function test if a file is available
    - File exist
    - File is not used by a process
    - File size is stable

    Code:
    #
    # Function : is_file_arrived file
    # Arg(s)   : file = file to verify
    # Output   : None
    # Status   : 0 = yes file arrived, 1 = no
    # Env.     : VFA_WAIT : interval (secs) for file size check (def=5)
    #
    
    verify_file_arrival() {
       [ -z "$1" ] && return 1
       _ifa_File=$1
       _ifa_Arrived=1
       if [ -f "$_ifa_File" -a -z "`fuser $_ifa_File 2> /dev/null`" ] ; then
          _ifa_Size1=`ls -l $_ifa_File 2>/dev/null | awk '{print $5}'` 
          sleep ${VFA_WAIT:-5}
          _ifa_Size2=`ls -l $_ifa_File 2>/dev/null | awk '{print $5}'` 
          [ ${_ifa_Size1:-1} -eq ${_ifa_Size2:-2} ] && _ifa_Arrived=0
       fi
       return $_ifa_Arrived
    }
    
    #
    # Main. 
    #
    
    if is_file_arrived /home/dba/$DATA_FILENAME 
       then echo "Arrived"
       else echo "Not arrived"
    fi
    Jean-Pierre.

  4. #4
    Join Date
    Sep 2003
    Posts
    71
    Just curious to know if there another way to check for a file in use( by a process) ? i don't have root priviledge at my unix system(HP-unix) to use 'fuser'

  5. #5
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Are you sur that you need privilege to use 'fuser' ?
    Im working with AIX, my user is not root :

    ksytws:> id
    uid=401(ksytws) gid=400(tivoli) groups=1(staff)
    ksytws> ls -l /tmp/jgu.txt
    -r-------- 1 ucogl pel 18700 Feb 26 15:58 /tmp/jgu.txt
    ksytws:> more /tmp/jgu.txt
    /tmp/jgu.txt: Permission denied
    ksytws:> fuser /tmp/jgu.txt
    /tmp/jgu.txt: 98396
    Jean-Pierre.

  6. #6
    Join Date
    Sep 2003
    Posts
    71
    man fuser|grep user

    fuser - list processes using a file or file structure
    -u Display the login user name in parentheses following each
    user name - is written to standard error.
    You must be superuser to use fuser.

  7. #7
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Another difference between AIX and HP-UX ....

    You can also use the command lsof to list open files.
    The command is not available on all systems.

    Try : lsof -h
    or /usr/local/bin/lsof -h
    Jean-Pierre.

  8. #8
    Join Date
    Feb 2004
    Posts
    37

    Re: Verify File Arrival

    Thanks for all the help.

  9. #9
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Just to correct the function name :

    Code:
    #
    # Function : is_file_arrived file
    # Arg(s)   : file = file to verify
    # Output   : None
    # Status   : 0 = yes file arrived, 1 = no
    # Env.     : VFA_WAIT : interval (secs) for file size check (def=5)
    #
    
    is_file_arrived () {
       [ -z "$1" ] && return 1
       _ifa_File=$1
       _ifa_Arrived=1
       if [ -f "$_ifa_File" -a -z "`fuser $_ifa_File 2> /dev/null`" ] ; then
          _ifa_Size1=`ls -l $_ifa_File 2>/dev/null | awk '{print $5}'` 
          sleep ${VFA_WAIT:-5}
          _ifa_Size2=`ls -l $_ifa_File 2>/dev/null | awk '{print $5}'` 
          [ ${_ifa_Size1:-1} -eq ${_ifa_Size2:-2} ] && _ifa_Arrived=0
       fi
       return $_ifa_Arrived
    }
    
    #
    # Main. 
    #
    
    if is_file_arrived /home/dba/$DATA_FILENAME 
       then echo "Arrived"
       else echo "Not arrived"
    fi
    Jean-Pierre.

  10. #10
    Join Date
    Feb 2004
    Posts
    37
    Thanks . I apreciate all the help!

Posting Permissions

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