Deleting code
Try formatting your file_list.ind
file like this:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2
Then in you script do this:
while read fname
do
fname=${fname/(sysdate)/$TIMESTAMP}
if [ -f $location1/$fname ]; then
echo " $fname exists in $location1" > $log_file
else
# ...
fi
done < $master_file_list
With TIMESTAMP=$(date "+%Y%m%d%H%M%S")
I doubt that any files are matched when "sysdate is the date of that day".
Your $log_file
will be overwritten with every new redirection.
After sending $mail_body
, you spend quite some effort to create another one never to be used.
cat $master_file_list|awk '{ print $1 }'| while read fname
do ...
done
could be replaced by
while read fname DUMMY
do ...
done < $master_file_list
I don't see any way to guess at what unspecified magic will translate:
Name in /scripts/data/file_list.ind Actual name to use
=================================== ==========================================================
file.txt file_claim_(systemdate)_mly.dat
file2.txt file_claim(systemdate)_mly.bz2
and so on file_claimSomeStringMaybe(systemdate)_mly.AbsolutelyNoIdea
... ???
And, you have given us no indication of what format is used to display your systemdate
... could it be: DayOfWeek, MonthName DayOfMonth, Year; YYYYMMDD; MM-DD-YYYY; or something very complicated like MM/DD/YYYY (which is a pathname, not a filename)? Of course, if you use the 1st form of systemdate above your (unneeded) awk
script won't work. And, with parentheses in your file names (and, especially if you include <space>s in your file names), you absolutely have to quote all expansions of the variable(s) that contain those file names.
All of the uses of cat
and awk
in your script should be removed to make your script more efficient. And expansions of all of your variables should be quoted. But, without a clear definition of the mapping of the filenames in /scripts/data/file_list.ind
to the filenames you need to process, there isn't much we can do to help you fix your code.
You haven't said what operating system or shell you're using. From your definition of the variable _ID
, I would assume you're using a Solaris/SunOS system and that you are not using /bin/sh
as your shell (since you're using the $(command)
form of command substitution). If you're using a Solaris 10 system and ksh
(which on Solaris 10 is a 1988 version of the Korn shell) as your shell, the variable substitutions suggested by Chubler_XL in post #2 won't work. Any time you post a shell script and ask for help modifying it, please tell us what operating system (including the version) and shell you're using so we can make suggestions that will work in your environment.
Thank you for your reply.i did take your suggestion removed Cat command and did below modifications and its working now
file_list.ind
file like this:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2
Then in you script do this:
DAT="dat"
while read fname
do
fname=${fname/(sysdate)/$TIMESTAMP}
if [ -f $location1/$fname*$DAT ]; then
echo " $fname.dat exists in $location1" > $log_file
else
# ...
fi
It's working fine for
file_claim_(sysdate)_mly.dat
But not for
file_claim_(sysdate)_mly.bz2
I did add else if condition for bz2 file it does not seem to work .i just wanna trigger alert if both of these doesn't exist or any one from both name should be printed in mail I am sending.
---------- Post updated at 12:49 PM ---------- Previous update was at 12:34 PM ----------
Thank you for your reply.
I am just new to shell script trying my best to make things work .i will try to answer your questions.Yes I did remove cat and awk
My requirement is simple I will be receiving files daily in directory /apps/data
and format of files will be SOME_TEXT_SYSDATE(YYYYMMDD)_number(0-9)_of_mly.dat
and one more file SOME_TEXT_SYSDATE(YYYYMMDD)_number(0-9)_of_mly.bz2
.Number in file name is random it can be anything.I need to generate alert with missing file name if single or both files are missing.I am using Linux OS.
---------- Post updated at 12:57 PM ---------- Previous update was at 12:49 PM ----------
There is change in format of file
SOME_TEXT_SYSDATE(YYYYMMDD)_number(0-9)_of_mly.bz2
we have random number between (0-9) in file name.
I'd propose you post some representative samples from real data / structures and detailed error messages so we can stop wild guesses and start analysing and eventually solving the problem. You may want to run the script with the -x
(xtrace) option set so everybody can see what is going on.
Look at the text marked in red from your post above. Note that the names you are using are inconsistent. If you are looking for a filename with an underscore between claim
and today's date, you won't find it using a pattern that does not have an underscore in that position. (Close may count in horseshoes; but not in programming. )