?
Solved

FILe WATCHER

Posted on 2006-07-06
15
Medium Priority
?
678 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
ID: 17052239
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 1200 total points
ID: 17060647
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
ID: 17061448
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:sumanth_ora
ID: 17077148
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
ID: 17077744
yes you can
0
 

Author Comment

by:sumanth_ora
ID: 17085123

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
ID: 17085291
It looks like you've split the <<<EOF - this must be kept together.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17088123
> 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
ID: 17089830


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
ID: 17089837
    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 800 total points
ID: 17090501
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
ID: 17092884
$ 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
ID: 17093270
> 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
ID: 17099105
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
ID: 17099757
you posted the script wit returns, don't knwo if that is what you realy want
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

621 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