ls every 5 minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls every 5 minutes
# 1  
Old 05-14-2010
ls every 5 minutes

I have to check for a directory content: every time it is filled with a file, I have to launch a bash script.

So: how to do an
Code:
ls

every 5 minutes (avoiding cron), telling the script to start if the file has appeared in the dir?

Have you got better ideas?

Thanks in advance!
# 2  
Old 05-14-2010
Infinite loop + sleeping for 300 seconds? Have the script launch itself every 5 minutes using at? If you're on Linux, use inotify?
# 3  
Old 05-14-2010
One idea:

Code:
while true
do
        if [ ! -f filename ]
        then
                sleep 300
        else
                ./scriptname
                break
        fi
done

The trouble with this type of process is the tendency to pick up part written files. It is better if the process creating the file does so under a temporary filename and then renames the file when the file is complete.
# 4  
Old 05-14-2010
The problem is that the file name changes every time (it is an image to process) and I can't change its management (renaming it, etc...)

It just falls in this dir from another system and when it is completely transferred, I have to start the process.

Yes I use Linux...how does inotify works? Can you give me an example?
# 5  
Old 05-14-2010
What about this?:

Code:
nohup watch -n300 "test -f /path/to/your/directory/*.*; if [ $? -eq 0 ]; then /your/script; else :; fi" &> /dev/null &

Assuming your directory has only one file, regardless of the name.
# 6  
Old 05-14-2010
Code:
#!/bin/bash
until ls * ; do sleep 300; done    # Wait until a file is present
while true    # Wait until the file stops growing
do
    X="$(ls -l)"
    [ "$X" = "$Y" ] && break
    Y="$X"
    sleep 1
done
# Put your code here

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

3. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

4. Linux

Interface goes down after 2 minutes

Hi all, I am using an F5 LTM Load balancer VM. Its network config is as follows: eth0 Link encap:Ethernet HWaddr 00:50:56:01:01:FA inet addr:192.168.2.104 Bcast:192.168.2.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fe01:1fa/64 Scope:Link UP... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

5. Solaris

Lock password for 15 minutes

Hi, Can we configure Solaris-10 and Solaris-11, which can lock any user for 15 minutes after 5 unsuccessful logins ? I am trying to search, if it is possible but not able to find. Regards (1 Reply)
Discussion started by: solaris_1977
1 Replies

6. UNIX for Dummies Questions & Answers

Subtract minutes from date

Hi, I am reading a particular date from a file using below command WFLWDATE=$(sed '2q;d' FileA.prm) The echo command outputs the correct date in variable WFLWDATE Now I want to subtract 5 minutes from this variable. I am on AIX and unable to get anything working as expected. Can you... (1 Reply)
Discussion started by: vrupatel
1 Replies

7. UNIX for Dummies Questions & Answers

Minus 5 minutes

Hi, I need to subtract 5 minutes from the date. Example $date +"%Y-%m-%d-%H.%M.%S" displays 2014-06-26-06.06.38 I want to show it as 2014-06-26-06.01.38 (5 mins are subtracted from date) Any help would be appreciated. I am currently on AIX version 6.1 -Vrushank (10 Replies)
Discussion started by: vrupatel
10 Replies

8. Shell Programming and Scripting

To get the previous 5 minutes

Hi I need to get the previous 5 minutes from the currnet time as given below. Please help. Current time : date +%d-%m-%Y_%H-%M output : 16-05-2012_15-05 I need the previous 5 minutes of the above output , Required output: 16-05-2012_15-04 16-05-2012_15-03... (4 Replies)
Discussion started by: Kanchana
4 Replies

9. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies
Login or Register to Ask a Question