I have a filesystem called "datafiles" that occasionally has files with the structure "upload.0002" or "upload.0003", etc.. I need to create a Korn script that can be run via CRON that will do the following:
1. Check in my "datafiles" directory for any files that have those names.
2. Insure that any files found with that naming structure have completely uploaded.
3. Look at the extension that the file has (a.k.a. "0002", "0003", "0004", etc.) and capture it as a variable.
4. Re-name the file to the "str####.asc" structure (i.e. upload.0002 would become str0002.asc)
4. Run a command called "prep" followed by the correct variable for that file, so "str0002.asc" would have "/prep 0002" run for it and "str0003.asc" would have "/prep 0003" run for it...
5. Wait 300 seconds and repeat, until the process is killed by CRON
Something like:
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
...should check for the file and make sure it is done processing (thanks Damian...), but how to get the script to capture the extension and run arguments against a file using that extension as a variable I'm puzzled?
1. Check in my "datafiles" directory for any files that have those names.
2. Insure that any files found with that naming structure have completely uploaded.
3. Look at the extension that the file has (a.k.a. "0002", "0003", "0004", etc.) and capture it as a variable.
4. Re-name the file to the "str####.asc" structure (i.e. upload.0002 would become str0002.asc)
4. Run a command called "prep" followed by the correct variable for that file, so "str0002.asc" would have "/prep 0002" run for it and "str0003.asc" would have "/prep 0003" run for it...
5. Wait 300 seconds and repeat, until the process is killed by CRON
Something like:
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
...should check for the file and make sure it is done processing (thanks Damian...), but how to get the script to capture the extension and run arguments against a file using that extension as a variable I'm puzzled?