If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Verify File Arrival

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-04, 15:58
gomes009 gomes009 is offline
Registered User
 
Join Date: Feb 2004
Posts: 37
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.
Reply With Quote
  #2 (permalink)  
Old 02-25-04, 16:36
nezumi nezumi is offline
Registered User
 
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****
akrosum@yahoo.com
Reply With Quote
  #3 (permalink)  
Old 02-26-04, 03:52
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #4 (permalink)  
Old 02-26-04, 09:49
skd skd is offline
Registered User
 
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'
Reply With Quote
  #5 (permalink)  
Old 02-26-04, 10:07
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Are you sur that you need privilege to use 'fuser' ?
Im working with AIX, my user is not root :

Quote:
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.
Reply With Quote
  #6 (permalink)  
Old 02-26-04, 10:18
skd skd is offline
Registered User
 
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.
Reply With Quote
  #7 (permalink)  
Old 02-26-04, 11:12
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #8 (permalink)  
Old 02-27-04, 10:03
gomes009 gomes009 is offline
Registered User
 
Join Date: Feb 2004
Posts: 37
Re: Verify File Arrival

Thanks for all the help.
Reply With Quote
  #9 (permalink)  
Old 02-27-04, 12:32
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #10 (permalink)  
Old 02-29-04, 01:22
gomes009 gomes009 is offline
Registered User
 
Join Date: Feb 2004
Posts: 37
Thanks . I apreciate all the help!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On