Watch a directory for new files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Watch a directory for new files
# 1  
Old 11-02-2012
Watch a directory for new files

In Solaris, and other distros without the "watch" command, use the following code watch for files added to a directory.

Code:
#!/bin/bash

while [ 1 ];
do
        watchdir=/var/tmp
	newfile=$watchdir/.newer
        touch $newfile
        find $watchdir -newer $newfile; 
	touch -a -m $newfile;
        sleep 5;
done


Last edited by os2mac; 11-02-2012 at 07:42 PM.. Reason: for correction and formatting.
# 2  
Old 11-02-2012
I don't see a question raised here!!
# 3  
Old 11-02-2012
No question, sharing the information. I see this come up a lot.
# 4  
Old 11-02-2012
Yup ... and by the way, you can also just use the watch command instead:

Code:
man watch

(see -d option and -n option)
This User Gave Thanks to ctsgnb For This Post:
# 5  
Old 11-02-2012
FYI: os2mac's second post here was in the moderation queue... I approved it just a second before ctsgnb's reply.
# 6  
Old 11-02-2012
Quote:
Originally Posted by ctsgnb
Yup ... and by the way, you can also just use the watch command instead:

Code:
man watch

(see -d option and -n option)
you are assuming of course everyone is on your distro:

Code:
man watch
No manual entry for watch.


Smilie
# 7  
Old 11-02-2012
You said that, but didn't mention what 'distro' you are on... Smilie
These 2 Users Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. Shell Programming and Scripting

Watch a directory for files with a pecific pattern

I dont know if this possible. I need to watch a directory and if any file gets appeneded with a particular entry say, nologin.php, we should get output of that. (1 Reply)
Discussion started by: anil510
1 Replies

4. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. UNIX for Advanced & Expert Users

How to rsync or tar directory trees, with hidden directory, but without files?

I want to backup all the directory tress, including hidden directories, without copying any files. find . -type d gives the perfect list. When I tried tar, it won't work for me because it tars all the files. find . -type d | xargs tar -cvf a.tar So i tried rsync. On my own test box, the... (4 Replies)
Discussion started by: fld2007
4 Replies

7. Shell Programming and Scripting

KSH Script to watch log files for 2 strings

Hi all, How can I do a ksh script to watch a log file for 2 specific alarms that have one this string : "Connection Error" and the other one: "Failure in sending". I would like to watch for these two alarms in the log and then if each of them repeats for about 30 times to go kill 2 processes. ... (1 Reply)
Discussion started by: Pouchie1
1 Replies

8. UNIX for Advanced & Expert Users

Watch directory and move specific file extensions

Hi all, This is actually more for my lazyness then anything else, but I think others might find it useful to use as well. Basically this is what I am trying to achieve... In my ubuntu home dir under Downloads is where firefox saves everything by default, now I know that you can manually... (3 Replies)
Discussion started by: STOIE
3 Replies

9. UNIX for Dummies Questions & Answers

Which log files to watch for size?

I'm rusty with unix admin, and I was just informed by a peer in another city that I need to watch my unix log files for size, but she never told me which ones to watch - and of course, now she's gone for two weeks! I am using Sco OpenServer 5.5 (I believe), can anyone tip me off on the trouble log... (3 Replies)
Discussion started by: citygov
3 Replies

10. UNIX for Dummies Questions & Answers

script to watch changes on a directory

Hi, everybody I want to know hot to watch changes on a dir, for example if someone changes a file inside it, with an script. I've tried using md5sum and then diff, sadly with no success. I use md5sum for single files, but doesn't work for directories. The idea is take a snapshot with md5sum,... (4 Replies)
Discussion started by: piltrafa
4 Replies
Login or Register to Ask a Question