The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Performing Script on Multiple Files zanetti321 UNIX for Advanced & Expert Users 3 04-16-2008 07:42 AM
Script to delete all data from multiple files uni_ajay_r Shell Programming and Scripting 5 03-29-2006 08:05 AM
Need a script to delete multiple files navycow UNIX for Dummies Questions & Answers 3 01-16-2006 11:50 AM
Combining Multiple files in one in a perl script rahulrathod Shell Programming and Scripting 1 12-17-2005 10:51 PM
Perform a command to multiple files mcgrawa UNIX for Dummies Questions & Answers 4 09-25-2003 01:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-09-2006
Registered User
 

Join Date: Jul 2005
Posts: 32
Question Script to perform some actions on multiple files

I have this Korn script that I wrote (with some help) that is run by cron. I basically watches a file system for a specific filename to be uploaded (via FTP), checks to make sure that the file is no longer being uploaded (by checking the files size), then runs a series of other scripts. The script is in a never ending loop that is "throttled" so that it when it is finding matching files its loop is shorter, but once it stops finding mathing files (in the monitored file system) it slow down until it finds another matching file.

Everything works great except that now I need to have the script monitor the same filesystem for two filenames. Actually they are the same filename but sometimes they are in ALL CAPS and sometimes they are not (for example I might get an upload.0002 or an UPLOAD.0002). Here is the script:

Code:
#!/bin/ksh
#
# Function : is_file_arrived file
# Arg(s)   : file = file to verify
# Output   : None
# Status   : 0 = yes file arrived, 1 = no
# Env.     : IFA_WAIT : interval (secs) for file size check (def=5)
#
 
is_file_arrived() {
   [ -z "$1" ] && return 1
   local file=$1
   local arrived=1
   local size1 size2
   if [ -f "$file" -a -z "$(fuser $file 2> /dev/null)" ] ; then
      size1=$(ls -l $file 2>/dev/null | awk '{print $5}')
      sleep ${IFA_WAIT:-15}
      size2=$(ls -l $file 2>/dev/null | awk '{print $5}')
      [ ${size1:-1} -eq ${size2:-2} ] && arrived=0
   fi
   return $arrived
}
 
 
processFile ()
{
   local fileName=$1
   local fileExtension=$2
   local fileNewName="/datafiles/str${fileExtension}.asc"
   local filePrintPath="/print"
   local fileTmpPath="/tmp"
   local fileODIName="str${fileExtension}.pos"
   mv -Eignore $fileName $fileNewName      # Add status check
   prepup $fileNewName $fileExtension
   mv -Eignore  $filePrintPath/$fileODIName $fileTmpPath/$fileODIName
   save2tmp $fileExtension
   call_siu $fileExtension
}
 
# Main Processing
 
nsec=1
#hile :
while [[ "$(date +%H%M)" -lt 2329 ]]
do
   for fileName in /datafiles/UPLOAD.[0-9][0-9][0-9][0-9]
   do
      fileExtension=${fileName#*.}
      is_file_arrived "$fileName" && nsec=1 && processFile $fileName $fileExtens
ion
   done
   sleep $nsec
   case $nsec in
      1)   nsec=15;;
      15)  nsec=45;;
      45)  nsec=90;;
      90)  nsec=300;;
      300) nsec=600;;
      600) nsec=900;;
      *)   nsec=1800;;
   esac
done
...how can I add additional filenames to the expression:

Code:
for fileName in /datafiles/UPLOAD.[0-9][0-9][0-9][0-9]
Reply With Quote
Forum Sponsor
  #2  
Old 06-12-2006
grial's Avatar
El UNIX es como un toro
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Quote:
Originally Posted by heprox
...how can I add additional filenames to the expression:

Code:
for fileName in /datafiles/UPLOAD.[0-9][0-9][0-9][0-9]
Very simple. Depends on what you want:
- Every file in /datafiles:
Code:
for fileName in /datafiles/*; do
   whatever_you_want
done
- Specific files inside /datafiles:
Code:
for fileName in /datafiles/file1 /datafiles/file2 /datafiles/file3; do
   whatever_you_want
done
If you only want to ignore case, use:

/datafiles/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9]


Regards.
Reply With Quote
  #3  
Old 06-12-2006
Registered User
 

Join Date: Jul 2005
Posts: 32
The syntax for:

Code:
/datafiles/[Uu][Pp][Ll][Oo][Aa][Dd].[0-9][0-9][0-9][0-9]
...was exactly what I was looking for, thanks. Worked like a charm.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0