Alert for missing file in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alert for missing file in directory
# 1  
Old 02-22-2017
thanks for help

Deleting code

Last edited by Adfire; 02-24-2017 at 12:29 PM..
# 2  
Old 02-22-2017
Try formatting your file_list.ind file like this:

Code:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2

Then in you script do this:

Code:
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

# 3  
Old 02-22-2017
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.
Code:
cat $master_file_list|awk '{ print $1 }'| while read fname
  do ...
  done

could be replaced by
Code:
while read fname DUMMY
  do ...
  done < $master_file_list

# 4  
Old 02-22-2017
I don't see any way to guess at what unspecified magic will translate:
Code:
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.
# 5  
Old 02-22-2017
Quote:
Originally Posted by Chubler_XL
Try formatting your file_list.ind file like this:

Code:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2

Then in you script do this:

Code:
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

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:

Code:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2

Then in you script do this:

Code:
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
Code:
file_claim_(sysdate)_mly.dat

But not for
Code:
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 ----------

Quote:
Originally Posted by Don Cragun
I don't see any way to guess at what unspecified magic will translate:
Code:
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 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 ----------

Quote:
Originally Posted by Chubler_XL
Try formatting your file_list.ind file like this:

Code:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2

Then in you script do this:

Code:
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

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.

Last edited by RudiC; 02-22-2017 at 02:38 PM..
# 6  
Old 02-22-2017
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.
# 7  
Old 02-22-2017
Quote:
Originally Posted by Adfire
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:

Code:
file_claim_(sysdate)_mly.dat
file_claim(sysdate)_mly.bz2

Then in you script do this:

Code:
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
Code:
file_claim_(sysdate)_mly.dat

But not for
Code:
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.

... ... ...
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. Smilie )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to check directory and create missing folder from file

In the below bash I am trying to ensure that all folders (represented by $folders) in a given directory are created. In the file f1 the trimmed folder will be there somewhere (will be multiple trimmed folders). When that trimmed folder is found (represented by $S5) the the contents of $2 printed... (19 Replies)
Discussion started by: cmccabe
19 Replies

2. Shell Programming and Scripting

Systemd errors of missing file “No such file or directory” inspite of file being present

The contents of my service file srvtemplate-data-i4-s1.conf is Description=test service for users After=network.target local-fs.target Type=forking RemainAfterExit=no PIDFile=/data/i4/srvt.pid LimitCORE=infinity EnvironmentFile=%I . . . WantedBy=multi-user.target (0 Replies)
Discussion started by: rupeshkp728
0 Replies

3. Shell Programming and Scripting

CLI script for emailing alert if files missing in dir

thread removed (4 Replies)
Discussion started by: billabongjimmy
4 Replies

4. UNIX for Dummies Questions & Answers

Directory missing .how to find the cause .

Hi, i am using rhel6.4, i lost my directory under /home .is there any way to find the reason how that directory deleted and how to recover deleted folder. (2 Replies)
Discussion started by: sayhirams
2 Replies

5. Red Hat

Directory missing

Hi, Archive backup log is /oracle_backup/logs . Since yesterday /logs directory is missing.How to find What has changed since the last time it has worked? OS -- Linux 2.6 x86_64 Regards, Maddy (4 Replies)
Discussion started by: Maddy123
4 Replies

6. Shell Programming and Scripting

Help need to find out the missing files in the directory

Hi All, Below is my requirement. I want to display the missing files in the directory. Below is my example From SFTP we are copying 10 files every day. if any files missed on that day need to send a notification with missing files Test1.dat 20121107_00_file.csv 20121107_01_file.csv... (8 Replies)
Discussion started by: bbc17484
8 Replies

7. UNIX for Advanced & Expert Users

Solved: Missing whatis file from my /usr/shar/lib directory...

My whatis file is missing from my /usr/share/lib directory. I know I can recreate it by using catman -w command. My question is, why do all of my other servers have it and this one doesn't. Maybe due to a recent move of old to new servers and it just wasn't copied over. Unlikely, 'cause all... (0 Replies)
Discussion started by: zixzix01
0 Replies

8. Shell Programming and Scripting

Script to send an alert if a file is present in a directory for 10 min

hi, A script which look into a directory and send an alert via a mail. If there is any file exisiting in a directory for more then 10 min. (5 Replies)
Discussion started by: madfox
5 Replies

9. Solaris

Missing Base Directory

Hey all, I'm attempting to migrate a zone from one system to another, but I noticed that on the new system ssl BASEDIR was missing. I was wondering if creating the directory path for this would fix the issue when I migrate files over. SSL is installed on the new system but does not show a... (1 Reply)
Discussion started by: em23
1 Replies

10. Shell Programming and Scripting

If any file resides for more than an hour in this directory then to raise an alert

Hi If there is a file upload done from a remote server and if the file remains without being extracted for more than an hour, I need to identify the files and create an alert message to the users in the other end. please help me writing a shell script for it. Regards Yazhini (2 Replies)
Discussion started by: yazhini.t
2 Replies
Login or Register to Ask a Question