The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to copy and repeat falcondown01 Shell Programming and Scripting 4 09-07-2007 09:15 PM
Search for string and display those NOT found John Rihn Shell Programming and Scripting 17 05-22-2007 09:22 AM
Get line1 and line4 in a repeat pattern file bobo UNIX for Dummies Questions & Answers 3 10-25-2006 12:11 PM
Recursive Search and replace only when found string umen Shell Programming and Scripting 1 05-07-2006 02:20 PM
Repeat Commands dereckbc UNIX for Dummies Questions & Answers 6 01-04-2005 11:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2008
santosham santosham is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 17
search for a file, if not found sleep and repeat it for 3 hrs

Hi,

Can someone help me with this script ....

I need a ksh script, which will search for a specific file in a directory, if file not found sleep for 10 mins and search again, if still not found sleep again for 10 mins and so on .... it should search for that file for 3 hours and if that file is still not found, then it should send a e-mail.

Appriciate your help with this ...

Thanks,
Sant
  #2 (permalink)  
Old 10-09-2008
treesloth treesloth is offline
Registered User
  
 

Join Date: Oct 2008
Location: Orem, Utah
Posts: 73
This won't be a complete answer, as ksh really isn't my thing; however, I would base a quick and dirty script of this kind you describe on the fact that there are 18 10-minute periods in 3 hours. So, something like this might be a reasonable framework:


Code:
integer n=0
while ((n <= 18));
do
     if [[ -e filename ]]
          then
               integer n=19
          else
               if [[ n = 18 ]]
                    Send your mail with whatever command you need....
               else
                    sleep 600
               fi
     fi
n++
done

Anyway, that's the idea... it'll require lots of work, and I would be stunned if it ran without significant alteration. Some of it probably isn't even valid ksh. Hopefully it gives you a starting point, though.
  #3 (permalink)  
Old 10-09-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,577
>Can someone help me with this script ....

Where is it?
  #4 (permalink)  
Old 10-09-2008
santosham santosham is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 17
here is the script i tried ..

Here is the script i tried ...

#! /usr/bin/ksh

File="abc.txt"

if [ -f $DIR/$File ]
then
echo "File Found"
break
else
i = 0
echo "File Not Found! Wait for 10 mins and try searching again!"
sleep 10m
i = i + 10
if [i > 120]
then
echo "Alert!! File not found for 2 hrs!!" | mailx -s "File not found" abc@abc.com
break
fi
fi
  #5 (permalink)  
Old 10-09-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,577
By courtesy of era:

a self-scheduling at job is also an option:.

Code:

#!/bin/sh
: your code here # you would need a counter to end (see above thread of treesloth) and mail after 3 hours of unsuccessfull attempts...etc..

echo "$0" "$@" | at now + 10 minutes
  #6 (permalink)  
Old 10-09-2008
santosham santosham is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 17
Thanks friends

Thanks for all ur help ...

here goes the final script ...


Code:
while (( $i <= 60 ))
do
  if [ -f $File ]
  then
      echo "File Found"
      break
  else
      sleep 10
      i=`expr $i + 10`
      if [ $i -gt 60 ]
      then
          echo "ALERT!!" | mailx -s "ALERT!!" ${ID}
      else
          sleep 1
      fi    
  fi
done

Closed Thread

Bookmarks

Tags
search file for 3 hrs, sleep for few mins and restart

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0