Loop to check for file up to 3 times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loop to check for file up to 3 times
# 1  
Old 07-11-2008
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  
Old 07-11-2008
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  
Old 07-16-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check same process running 10 times?

At run time Without knowing job name how to check the job running in specific user "ABCD" ,If the running job duplicate more then 10 then script it self send alert message to the users with the process ID name so that will kill the processed to avoid hung issue ,tried below script please check and... (15 Replies)
Discussion started by: Kalia
15 Replies

2. Shell Programming and Scripting

Loop to execute 2 times and send an email alert

After the successful start of server, it should check the status again, if it is not running ,it should go through the loop for 2 times. Even after two times of execution if still the server is not running it should send an alert email. Please help (1 Reply)
Discussion started by: thomas9192
1 Replies

3. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

4. UNIX for Dummies Questions & Answers

How to check if the same file exists multiple times?

Hi Team , Is there a way I can check to see if the same file say , test.dat exists multiple times in the directory path ? Please help. Thanks Megha (5 Replies)
Discussion started by: megha2525
5 Replies

5. Shell Programming and Scripting

FASTEST way to loop a script 10k times

Is there any FASTEST way to loop a script 10k times my script works likes this c-randomnumbers-script -i input1.bed -g g19 -e DB >> output1 I need to run this 10k times by using consecutive outputs to get my final output i.e, output10000 c-random-script -i input1.bed -g g19 -e DB >>... (5 Replies)
Discussion started by: quincyjones
5 Replies

6. UNIX for Advanced & Expert Users

System call failed with 127 .. after 500 times when called in loop

Hi Experts, I have a code like this. ===== #include.... int main() { int count = 0; while(1){ printf("\n Interation number is: %d \n ",count); rv = system(" test.sh > log.txt " ); if (-1 == rv) { printf("Could not generate static log: error... (12 Replies)
Discussion started by: binnyjeshan
12 Replies

7. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

8. Shell Programming and Scripting

Script to check for the newest file mutiple times a day and SCP it to another server.

Hi, I need a sample of a script that will check a specific directory multiple times throughout the day, and scp the newest file to another server. Example: current file is misc_file.txt_02272011 (the last part is the date), once that has been secure copied, another one may come in later the... (1 Reply)
Discussion started by: richasmi
1 Replies

9. Shell Programming and Scripting

The loop was executed $count times

#!/bin/sh count=0 for i in 2 4 6 do echo "i is $i" count='expr $count + 1' done echo "The loop was executed $count times" with these scripts my output is : i is 2 i is 4 i is 6 The loop was executed expr $count + 1 times What should I do to get the value instead of 'expr... (17 Replies)
Discussion started by: ymwong
17 Replies
Login or Register to Ask a Question