Sponsored Content
Top Forums Shell Programming and Scripting Help needed for Sleep (File watcher) Post 302997501 by ace_friends22 on Monday 15th of May 2017 11:39:13 AM
Old 05-15-2017
Help needed for Sleep (File watcher)

Hi All,

I have a requirement, where I need to check for file. If file is not available then wait for 5 minutes and if it still not available, fail the process. It should check every one minute.

If File available in between, should start remaining process. Now my problem is, I have both part ready. But not able to understand where to put script logic, if file is available.

Ex: Wait for file, for 5 minutes, check every one minute

Code:
#!/bin/ksh
let tw=0
let num=60

while [ ! -f /home/aa.txt ]; do
sleep 60
tw=`expr ${tw} + ${num}`
if [ ${tw} -eq 300 ]
then
echo "Time exceed 5 minutes"
exit 1;
else
echo "Waiting for file, wait time exceeds ${tw}"
fi
done

Now, if file aa.txt is available at beginning or in between above , then I need to start working on it. I do not know where to keep that portion. Can somebody help me?

---------- Post updated at 09:09 PM ---------- Previous update was at 08:59 PM ----------

Sorry, I found solution. I have posted solution for same in 2008. Smilie

Apologize for this.

FileWatcher Script
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file watcher job

Hello, I am trying to create a file watcher script to check for a file until certain time and throw a message. can some one please help me if there is script handy ?? Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

2. UNIX for Advanced & Expert Users

File Watcher Anamolous Behaviour

My file watcher is scheduled to look for a File ABC.XYZ. Ideally when it find this file present in the directory it is looking in should end :b:, but this file watcher is wasting 6-9 minutes each day :eek: i am unable to understand why this file watcher is behaving in freakish manner...:confused: (1 Reply)
Discussion started by: sameerspice
1 Replies

3. Shell Programming and Scripting

File Watcher

Hi Please help me in this I want to execute a shell script abc.ksh. But I only want it to execute if file XYZ is not present. If file XYZ is present than I want to unix to sleep for 5 Sec and than agaian check for XYX existence. if it sleeps for more than 30 seconds ( 6 time )I want it to... (3 Replies)
Discussion started by: er_zeeshan05
3 Replies

4. Shell Programming and Scripting

File Watcher using autosys

Hi, Would like to kick off a script based on the file arrival using autosys but this has to monitor every second instead of a minute. Is there a better way to implement the monitor apart from cronjob and only need to use autosys in UNIX. Regards, Rajasilpa (0 Replies)
Discussion started by: rajasilpa
0 Replies

5. UNIX for Advanced & Expert Users

Need Script for File Watcher

Hi, I need a script for "FILE WATCHER" I have in a remote FTP location server named MAIN _104 EveryDay mrng 8 i hav to search couple of folders(COL, ATT, TRA) in that FTP server (MAIN_104), and if any files are present in that folders i hav to bring back to my computer and store it anywhere... (4 Replies)
Discussion started by: nani1984
4 Replies

6. Shell Programming and Scripting

File Watcher Help !!

Hi Experts I will have be having 3 types of files in directory file1_p0_date file1_p1_date file1_p2_date As soon as it sees any of the files it needs to kick off another process and also would need the file name For this I am creating a file watcher script which will look for file1* My... (2 Replies)
Discussion started by: westernmichnov
2 Replies

7. Shell Programming and Scripting

Help needed with File Watcher script

Hi all, I am writing a script to do the following: 1) Check if there are any new <csv> files (in abc directory) to process 2) If there is new file, then perform some operation on that file. 3) Move it to a different location(after step2 is successful) 4) Do further processing on the file ... (2 Replies)
Discussion started by: stunnerz_84
2 Replies

8. UNIX for Dummies Questions & Answers

Autosys file watcher

Hi friends, Instead of creating a script autosys 11.3 has a feature for filewatcher. Can anyone please share a link where ican create a file watcher job (more like manual). i need to create a filewatcher job where the job should search for a file for every 5 mins and send a mail whether the... (1 Reply)
Discussion started by: robertbrown624
1 Replies

9. Shell Programming and Scripting

Looking out for the file-watcher

Hi friends, I do not have much thoughts so need any help on the below issue: I need to create shell script that will find the files & throw an error through job (autosys) when file not found. Daily we use to receive 3 files from a system. Obstacles: 1) All 3 files names are same. 2)... (4 Replies)
Discussion started by: tush
4 Replies

10. Shell Programming and Scripting

File watcher script

if test -n "$(find/data/path/ 'filename.txst' -print-quit) then echo "file found" exit 0 else echo "file not found" exit 46 fi So I basically looking to understand the if test -n "$(find/data/path/ 'filename.txst' -print-quit) line. Pls help to elaborate what this command... (6 Replies)
Discussion started by: Nsharma3006
6 Replies
Config::Watch(3)					User Contributed Perl Documentation					  Config::Watch(3)

NAME
Log::Log4perl::Config::Watch - Detect file changes SYNOPSIS
use Log::Log4perl::Config::Watch; my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", check_interval => 30, ); while(1) { if($watcher->change_detected()) { print "Change detected! "; } sleep(1); } DESCRIPTION
This module helps detecting changes in files. Although it comes with the "Log::Log4perl" distribution, it can be used independently. The constructor defines the file to be watched and the check interval in seconds. Subsequent calls to "change_detected()" will o return a false value immediately without doing physical file checks if "check_interval" hasn't elapsed. o perform a physical test on the specified file if the number of seconds specified in "check_interval" have elapsed since the last physical check. If the file's modification date has changed since the last physical check, it will return a true value, otherwise a false value is returned. Bottom line: "check_interval" allows you to call the function "change_detected()" as often as you like, without paying the performing a significant performance penalty because file system operations are being performed (however, you pay the price of not knowing about file changes until "check_interval" seconds have elapsed). The module clearly distinguishes system time from file system time. If your (e.g. NFS mounted) file system is off by a constant amount of time compared to the executing computer's clock, it'll just work fine. To disable the resource-saving delay feature, just set "check_interval" to 0 and "change_detected()" will run a physical file test on every call. If you already have the current time available, you can pass it on to "change_detected()" as an optional parameter, like in change_detected($time) which then won't trigger a call to "time()", but use the value provided. SIGNAL MODE Instead of polling time and file changes, "new()" can be instructed to set up a signal handler. If you call the constructor like my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", signal => 'HUP' ); then a signal handler will be installed, setting the object's variable "$self->{signal_caught}" to a true value when the signal arrives. Comes with all the problems that signal handlers go along with. TRIGGER CHECKS To trigger a physical file check on the next call to "change_detected()" regardless if "check_interval" has expired or not, call $watcher->force_next_check(); on the watcher object. DETECT MOVED FILES The watcher can also be used to detect files that have moved. It will not only detect if a watched file has disappeared, but also if it has been replaced by a new file in the meantime. my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", check_interval => 30, ); while(1) { if($watcher->file_has_moved()) { print "File has moved! "; } sleep(1); } The parameters "check_interval" and "signal" limit the number of physical file system checks, simililarily as with "change_detected()". COPYRIGHT AND LICENSE
Copyright 2002-2009 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.1 2010-02-07 Config::Watch(3)
All times are GMT -4. The time now is 05:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy