FILe WATCHER

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
 





sumanth_oraAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
tacticalvehicleConnect With a Mentor Commented:
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
 
bpmurrayCommented:
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
 
bpmurrayCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
sumanth_oraAuthor Commented:
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
 
JJSmithCommented:
yes you can
0
 
sumanth_oraAuthor Commented:

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
 
bpmurrayCommented:
It looks like you've split the <<<EOF - this must be kept together.
0
 
ahoffmannCommented:
> 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
 
sumanth_oraAuthor Commented:


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
 
sumanth_oraAuthor Commented:
    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
 
ahoffmannConnect With a Mentor Commented:
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
 
sumanth_oraAuthor Commented:
$ sh Filewatcher1.sh


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


how about:
  man sh

6 days of try&error can save 42 minutes reading ;-)
0
 
sumanth_oraAuthor Commented:
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
 
ahoffmannCommented:
you posted the script wit returns, don't knwo if that is what you realy want
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.