#!/usr/bin/ksh
set -x
testfile=my.test.file.flag
echo ${testfile: (-4)}
#/home/maldohe/scripts/spawn1&
sleep 3
echo myspawn is now ending
exit
Background:
I am trying to extract the word flag from anf given file name. This is a demo script that I am working on to fix a production issue. We get FTP files from various place and each come with a "FLAG" file once the data file is received. I am want to trap for the "FLAG" file and do something with it before it gets processesd.
I am guessing you want to remove the .flag part from the filename.
This is called parameter substitution, you can look up the rest of the operator for this online or in your man page
Actually, I am reviewing all files received and the files with the word "FLAG" as part of the filename I need to suspend for a time. Normally, the word "FLAG" comes at the end of the file name.
Sorry, if my script find a file with the word "FLAG" in the name, I am going to move that file to a new location so that it does not get picked up by another deamon process until a later time.
---------- Post updated at 11:10 PM ---------- Previous update was at 11:05 PM ----------
If the initial script that I posted could work I could test for the existance for the word "FLAG" or at least test the return code $? i think.
#! /usr/bin/ksh
for file in *; do
if [[ "${file:(-4)}" == "flag" ]]; then
# Do some processing here. Maybe:
/bin/mv "$file" /tmp/
else
# Do something else. Maybe nothing.
:
fi
done