Solved

FILe WATCHER

Posted on 2006-07-06
15
651 Views
Last Modified: 2013-12-26
Hi,

I am looking for  a script  which will look for a file(any file)

Once script started it has to look for a file ..
if file  exists come out of the script  with success mail ..else keep in  sleep  for 5 mins  & look in for the file every 5 mins
MAx time:2 hours

If file didn't exists after 2 hours come out of the script with Failure mail
 





0
Comment
Question by:sumanth_ora
  • 6
  • 4
  • 3
  • +2
15 Comments
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
try:

export COUNT=0
while [ $COUNT -lt 24 ]
do
     export FOUND=`find . -name "$1" -print`
     if [ ! -z ${FOUND} ]
     then
          sendmail ....
     fi
     sleep 300
     export COUNT=`expr $COUNT + 1`
if
echo Couldn't find file $1 after two hours!
0
 
LVL 1

Accepted Solution

by:
tacticalvehicle earned 300 total points
Comment Utility
All respect to my previous collegue  
his script is good but I want only correct some details ( of course his script is functional )

-------------------------cut it to file------------------------------------------------
#!/bin/ksh
COUNT=0;                                                                                             # init  counter value
while [ $COUNT -lt 24 ]                                                                                    # cycle start
do
     FOUND=`find /var/somethink/yourwholepath/  -type f  -print`               # type only for files no dir sockets or else request was "for any files in dir.."
     if [ ! -z ${FOUND} ];  then
    # mail/sendmail/mailx it on you
     mail -s "File arived on the BOX!"  bart@yahoo.com <<< EOF
check your directoery on the box you received files
bla bla bla
bla bla bla
bla bla bla
EOF
     fi # end of IF
     COUNT=`expr $COUNT + 1`;  export is not nescesarry
     sleep 300; # sleep was moved I think its better sleep here as before
# 24 * 300s = max time which this script will running
if


#dont forgot "nohup ./myfilewatcher.sh" if you want run it from console and then logout !
0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
Good point about the nohup - I had forgotten about that. Presumably nobody wants to sit watching this chug along for a couple of hours :-)
0
 

Author Comment

by:sumanth_ora
Comment Utility
So based on the above example can I  do like this


COUNT=0;                
 while [ $COUNT -lt 24 ]                                                                                  
do
     FOUND=`find /apt/edw/cdw/Arrive.ind  -type f  -print`              
     if [ ! -z ${FOUND} ];  then
         mail -s "Indicator File arived on the BOX!"  xxxxx@yahoo.com <<< EOF
Received the Indicator file on %m%d%y %H%M%S
EOF
Exit 0
     fi
     COUNT=`expr $COUNT + 1`;  export is not nescesarry
     sleep 300; # sleep was moved I think its better sleep here as before
# 24 * 300s = max time which this script will running
done

mail -s "Indicator File was not arived on the BOX yet!"  xxxxx@yahoo.com<<< EOF
we haven't Received the Indicator file  on %m%d%y
EOF

Exit 1



0
 
LVL 6

Expert Comment

by:JJSmith
Comment Utility
yes you can
0
 

Author Comment

by:sumanth_ora
Comment Utility

Sh Filewatcher1.sh


COUNT=0;
 while [ $COUNT -lt 2 ]

do
 FOUND=`find /appl/edwhome/cdwhome/dev/cdf/scripts/Arrive.ind -type f  -print`

     if [ ! -z ${FOUND} ];  then
 mail -s "Indicator File arived on the BOX!" sumanth.gogineni@thehartford.com  <
<< EOF
Received the Indicator file on %m%d%y %H%M%S
EOF
Exit 0
     fi
     COUNT=`expr $COUNT + 1`;  export is not nescesarry
     sleep 100; # sleep was moved I think its better sleep here as before
# 24 * 300s = max time which this script will running
done

mail -s "Indicator File was not arived on the BOX yet!"  sumanth.gogineni@thehar
tford.com <<< EOF
Received the Indicator file on %m%d%y %H%M%S
EOF
Exit 1
~


I am getting the following error

Filewatcher1.sh[2]: Syntax error at line 6 : `<' is not expected.

0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
It looks like you've split the <<<EOF - this must be kept together.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> Filewatcher1.sh[2]: Syntax error at line 6 : `<' is not expected.

1. do yu have a proper hashbang line?
2.      COUNT=`expr $COUNT + 1`;  export is not nescesarry
    should be
         COUNT=`expr $COUNT + 1` #  export is not nescesarry
0
 

Author Comment

by:sumanth_ora
Comment Utility


COUNT=0;
 while [ $COUNT -lt 2 ]
do
 FOUND=`find /appl/edwhome/cdwhome/dev/cdf/scripts/Arrive.ind -type f  -print`

     if [ ! -z ${FOUND} ];  then
mail -s "Indicator File arived on the BOX!" sumanth.gogineni@thehartford.com <<<
EOF
Received the Indicator file on %m%d%y %H%M%S
EOF
Exit 0
     fi
     COUNT=`expr $COUNT + 1`; # export is not nescesarry
     sleep 100;
done
mail -s "Indicator File was not arived on the BOX yet!" sumanth.gogineni@thehart
ford.com <<<EOF
Received the Indicator file on %m%d%y %H%M%S
EOF
Exit 1


Same error


Filewatcher1.sh[2]: Syntax error at line 6 : `<' is not expected.

0
 

Author Comment

by:sumanth_ora
Comment Utility
    1  COUNT=0;
     2   while [ $COUNT -lt 2 ]

     3  do
     4   FOUND=`find /appl/edwhome/cdwhome/dev/cdf/scripts/Arrive.ind -type f  -
print`
     5       if [ ! -z ${FOUND} ];  then
     6  mail -s "Indicator File arived on the BOX!" sumanth.gogineni@thehartford
.com <<<EOF
     7  Received the Indicator file on %m%d%y %H%M%S
     8  EOF
     9  Exit 0
    10       fi
    11       COUNT=`expr $COUNT + 1`; # export is not nescesarry
    12       sleep 100;
    13  done
    14  mail -s "Indicator File was not arived on the BOX yet!" sumanth.gogineni
@thehartford.com <<<EOF
    15  Received the Indicator file on %m%d%y %H%M%S
    16  EOF
    17  Exit 1


Filewatcher1.sh[2]: Syntax error at line 6 : `<' is not expected.
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 200 total points
Comment Utility
replace
   6  mail -s "Indicator File arived on the BOX!" sumanth.gogineni@thehartford.com <<<EOF
by
   6  mail -s "Indicator File arived on the BOX!" sumanth.gogineni@thehartford.com <<EOF
0
 

Author Comment

by:sumanth_ora
Comment Utility
$ sh Filewatcher1.sh


mail: illegal option -- s
usage: mail [+] [-epqr] [-f file]
       mail [-dt] persons
Filewatcher1.sh[9]: Exit:  not found.
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> Filewatcher1.sh[9]: Exit:  not found.
exit


how about:
  man sh

6 days of try&error can save 42 minutes reading ;-)
0
 

Author Comment

by:sumanth_ora
Comment Utility
Here is the script I modified based on your suggestions..

It's working fine...

Can i use this script in Production environment  or do i need to any changes....



COUNT=0;
 while [ $COUNT -lt 2 ]

do
 FOUND=`find /appl/edwhome/cdwhome/dev/cdf/scripts/Arrive.ind -type f  -print`

     if [ ! -z ${FOUND} ];  then
mailx -s "Indicator File was arrived on the BOX!" sumanth.gogineni@thehartford.c
om <<EOF
Indicator File was arrived on the BOX! :  `date`
EOF
echo  "Indicator File was arrived on the BOX!" :  `date`
exit 0
     fi
     COUNT=`expr $COUNT + 1`
     sleep 100;
done
mailx -s  "Indicator File was not arived on the BOX yet!" sumanth.gogineni@theha
rtford.com <<EOF
Indicator File was not arrived on the Box yet!  :  `date`
EOF
echo "Indicator File was not arrived on the Box yet!"  :  `date`
exit 1
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
you posted the script wit returns, don't knwo if that is what you realy want
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now