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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script check for file, alert if not there, and continue checking until file arrives
# 1  
Old 09-20-2010
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 [no file] {
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 isn't there. So, I want it to continue checking the file until it arrives and only exit when the file shows up.
# 2  
Old 09-20-2010
To check for file in a loop you can do this:

Code:
until [ -f "myfilename" ]
do
sleep 30 ##set it so that does not add load on your system
done

Rest logic you can add I guess.
This User Gave Thanks to 116@434 For This Post:
# 3  
Old 09-20-2010
Quote:
Originally Posted by 116@434
To check for file in a loop you can do this:

Code:
until [ -f "myfilename" ]
do
sleep 30 ##set it so that does not add load on your system
done

Rest logic you can add I guess.

Thanks sir, I think that is what I was looking for.

So, if I only wanted it to mail on the first iteration is that possible? The sleep is that in seconds?

I also want to be able to send the file arrives. So, that will execute until the file arrives or won't execute until the file arrives?

I think i have my logic:

if [file in dir]
send file
exit
else{
mail users
until (file in dir)
{ send file
}
}

Last edited by markdjones82; 09-20-2010 at 02:45 PM..
# 4  
Old 09-20-2010
I guess do not put it into iteration, it can be done this way:

Code:
[ -f "myfilename" ] || mailx ...

sleep is in seconds. but still can refer your box manpage for detail.

The loop will execute until the file arrives.
# 5  
Old 01-04-2011
Alert if a file is not found

We receive a FTP everyday at a certain time in the morning. I want to write a script that would send email notification to all stakeholders, if the file has not arrived on any particular day.

I am new to UNIX and apart from the basic commands know very little about scripting. Can you please help me with this script and explain it as well so I could understand and do it on my own the next time such a task comes up.

Thanks a ton in advance.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script fro file check and load the trail file

Hi, Im going to use shell script for load the data into DB. First i need to read the trail file(csv file has two columns with comma separated ) like file name trail1024(last 4 digitsMMDD). In this trail file 27 entries will have like below,I need to read first csv file name and get the 4... (1 Reply)
Discussion started by: krajasekhar.v
1 Replies

2. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

3. Shell Programming and Scripting

Check log file size every 10 minute. Alert if log not update

How to check log size every 10min. by script (can use crontab) if log size not change with alert "Log not update" Base run on SunOS 5.8 Generic_Virtual sun4u sparc SUNW,SPARC-Enterprise logFiles="log1.log log2.log" logLocation="/usr/home/test/log/" Out put. Tue Jan 31... (3 Replies)
Discussion started by: ooilinlove
3 Replies

4. Shell Programming and Scripting

Check if file exists if not send an alert

Hi, Im looking to write a script to check if a file exists and if it doesnt then send an email out, Ive found the below code but I don't understand the ! in the if statement can anyone explain? Any help will be much appreciated #!/bin/bash if then echo "File not exists" |... (10 Replies)
Discussion started by: 02JayJay02
10 Replies

5. Shell Programming and Scripting

File checking script need help

Hi, Gurus, I need a scripts to check specified file if it exists or not at certain time (say every month between 5th and 7th). if file exists do something otherwise do another thing. can anybody help this? Thanks in advance :wall: (3 Replies)
Discussion started by: ken002
3 Replies

6. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

7. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies

8. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies

9. Shell Programming and Scripting

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.... (7 Replies)
Discussion started by: Jose Miguel
7 Replies

10. Shell Programming and Scripting

reading a file name as soon as that files arrives into a folder

Hi, Thanks in Advance.. i have the following requirement, some one please help me.. An unix shell script has to pick up the file name from a folder as soon as that file comes into that folder. Regards, Alo (6 Replies)
Discussion started by: dtazv
6 Replies
Login or Register to Ask a Question