Continue Script when File Found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Continue Script when File Found
# 1  
Old 11-06-2006
Continue Script when File Found

Hello All,

I am trying to write a script that will only continue executing my script if a file exits. I know the directory of the file, so its just a matter of seeing if the file exists yet. If the file has not yet been created, I want the script to wait 10 minutes (600 seconds) and try again. I was thinking of using the "until" command somehow, but can't figure it out. Please help!

Jose
# 2  
Old 11-06-2006
Which shell? Here is a possibility using ksh:
Code:
myfile=/path/to/file
while true
 do
  if [[ -a $myfile ]]; then
    echo "$myfile exists!"
  else
    sleep 600
  fi
done

# 3  
Old 11-06-2006
Excellent! I guess if I want it to validate if more than one file exists I would do the following:

myfile=/path/to/file
myfile2=/path/to/second/file

while true
do
if [[ -a $myfile && -a $myfile2]]; then
echo "$myfile exists!"
rest of code
else
sleep 600
fi
done

Thank you.

Jose
# 4  
Old 11-07-2006
You can also do :
Code:
required_files='/path/to/file1 /path/to/file2 /path/to/file3'
interval=600

for file in ${required_files}
do
   until [[ -a "${file}" ]]
   do
      sleep ${interval}
   done
done

echo "All required files found."

Jean-Pierre.
# 5  
Old 11-07-2006
Thank you. I'm assuming that

until [[ -a "${file}" ]]

will keep looping until it finds all files in required_files? Also, I'm guessing the rest of the code comes after the loops (after the last done statement). Thanks.

Jose
# 6  
Old 11-07-2006
yes .. u r correct .. be sure that the file which u r checking for, is stable. i.e if u r getting the file at runtime then the condition " if [ -a $filename ] " will be successful even when the file is being copied in the directory, where u r looking the file for.
# 7  
Old 11-07-2006
Quick question then. Why doesn't this code work? It keeps giving me a syntax error:

";" unexpected

Can this instance of the if statement only validate two conditions about the same file, and not check existence of one file and then existence of another?

myfile=/path/to/file
myfile2=/path/to/second/file

while true
do
if [[ -a $myfile && -a $myfile2]]; then
echo "$myfile exists!"
echo "$myfile2 exists!"
rest of code
else
sleep 600
fi
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Continue the loop if the value is not found

Dear Help, Is it possible to continue the loop by going to the next available value, if the 'expected value' is not found. I have a list of values which might not get incremented by fixed value and hence the loop could break and the script could terminate. Any suggestion is appreciated. ... (1 Reply)
Discussion started by: Indra2011
1 Replies

2. UNIX for Dummies Questions & Answers

File Not found - Bash script

I'm facing issues in executing the bash script of mine. This script will pick the latest file received and connects SFTP server and files is placed on this remote server. Error message Enter password: "File movement" sftp> cd Test sftp> put Test_File_201309.txt File "Test_File_201309.txt"... (6 Replies)
Discussion started by: parpaa
6 Replies

3. Shell Programming and Scripting

Execute script if a file is found

I'm trying to get the following to look for the newest powerpoint presentation and if it finds something then run a shell script named star_presentation.sh and if it doesn't then simply exit. Any help would be greatly appreciated. #!/bin/bash ppts=/ticker/powerpointshare find $ppts... (3 Replies)
Discussion started by: binary-ninja
3 Replies

4. Shell Programming and Scripting

How to continue running a script while offline?

Hi there, I'm not really stranger to Linux and shell scripting but I am to servers. Anyway, I usually run scripts on a shared science machine, accessible via ssh. My scripts are usually run with mpi, e.g. mpirun -np 16 ./my_script the things after entering the science machine and running... (6 Replies)
Discussion started by: matteo86
6 Replies

5. Shell Programming and Scripting

How to continue numbering after a regular expression has been found

Hello, I have a file starting with: fixedStep chrom=chrX start=1 step=1 0.930 0.955 0.972 0.985 0.993 0.995 0.994 0.990 0.984 0.971 0.942 0.944 0.971 fixedStep chrom=chrX start=200 step=1 0.987 (2 Replies)
Discussion started by: jpoldot
2 Replies

6. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

7. Shell Programming and Scripting

Restart and then continue script

How can I get a script to complete a update, varifiy completion, resboot, and continue with script? Is it possbile to get script to add itself to the "startup application" list #!/bin/bash clear sudo apt-get update #Verify/test the update completed #Reboot #Start/comtinue... (9 Replies)
Discussion started by: wolfgangcs
9 Replies

8. Shell Programming and Scripting

Doing a tail in a script and then return back and continue script

Hello all, I am trying to do a tail in a script. But when I quit the tail my script quits also. This is not what I want. I am struggling to get this done. #!/bin/bash askFile() { echo -n "Enter file: " read FILE } doTail() { tail -F "${1}" } askFile doTail... (4 Replies)
Discussion started by: markdark
4 Replies

9. Shell Programming and Scripting

How to continue script if right word is not entered?

Hello, I am writing a script and in this script, I want to be able to have the script continue running if the correct word is not entered... Here is an excerpt from me script: read request if ; then echo "You have asked for the System Temperature..." cat... (1 Reply)
Discussion started by: niconico96
1 Replies

10. Shell Programming and Scripting

continue line in perl script

HI , I am new to the perl , I am using a if condition and in that if condition i am checking 7 variables value. so it continue to second line .And if i user "\" for the continue line it showing error. Example : if(a >9 || b>8 || c> 10 \ d > 11) { print(); } The above statement is... (3 Replies)
Discussion started by: julirani
3 Replies
Login or Register to Ask a Question