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
looking for help with a dd loop check script angusyoung Shell Programming and Scripting 1 06-24-2008 07:51 AM
script to loop and check jumping seq. happyv Shell Programming and Scripting 1 10-05-2006 10:55 AM
maximum number of times - a file can be opened matrixmadhan High Level Programming 3 03-21-2006 11:24 AM
Counting Number of times a File is accessed pathanjalireddy Shell Programming and Scripting 1 04-11-2005 10:49 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 07-11-2008
JohnCrump JohnCrump is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Loop to check for file up to 3 times

Please forgive this I think rather basic question.

I have been away from UNIX for a very long time and am in need of some help.

I need to be able to check for the existance of a specific file name say 'file.dat' in a particular location

If the file exists then run a second process (at processname now)

If the file does not exist then sleep 5 minutes and look for it again for up to 3 times

Once the file has been found and processed once only then send a mail and finish

Any hints tips or specific examples would be appreciated

Running HPUX by the way

Thanks
  #2 (permalink)  
Old 07-11-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,770
Code:
#!/bin/ksh
file="/path/to/file.dat"

for i in 1 2 3
do
    if [[ -f $file ]] ; then
        echo "file found" | mailx -s "$file found `date`"  joeblow@somewhere.com
        break
    fi
    sleep 300   # five minutes
done
Start with this.
  #3 (permalink)  
Old 07-16-2008
JohnCrump JohnCrump is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Many thanks for your help.

I have made some progress using the code, but need some further help with the following

1 The process searches up to 3 times for the arival of a file. Once it has detected the file and processed the job , it is important that it does not do so again. How can I prevent this?

2 In this version of the code the script does not loop back to try again when the file is not found

#!/bin/ksh
file="/path/to/file/file.dat"


for i in 1 2 3
do
if [[ -f $file ]] ; then echo " file found"
at -f jtest_get_file.sh now
else
echo "File not found!".

break
fi
sleep 3 # 3 seconds will be 600
done



Regards
Closed Thread

Bookmarks

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 04:58 AM.


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