The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How Can I Easily Determine If A File Has been Added to a Directory goodmis UNIX for Dummies Questions & Answers 1 01-31-2007 06:56 PM
cannot determine current directory axes UNIX for Advanced & Expert Users 15 11-13-2006 07:39 AM
determine owner directory permissions from within the directory Sniper Pixie Shell Programming and Scripting 4 03-07-2006 05:06 PM
How to generate a configuration file easily and effectively? sarathytcs Shell Programming and Scripting 0 01-30-2006 09:51 AM
How to scan only new lines added in file? redlotus72 UNIX for Dummies Questions & Answers 3 04-28-2005 04:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-31-2007
goodmis goodmis is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 24
How Can I Easily Determine If A File Has been Added to a Directory

I am uploading files that need to be processed prior to uploading. I will put the files in a directory. My question is how can I write an easy process to kick off a script once a file has been added? Is there an easy way to determine if a file has been added to a directory?

Thanks
  #2 (permalink)  
Old 01-31-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
At the end of you script create a file in the same directory with a name you like.

At the start of your script search for files which are newer than the file you created in your previous run.

script:
-------------------------------------------------------------------
#!/usr/bin/ksh

cd /somedir
for FILE in `find ./* -prune -type f -newer ./TIMEFILE`
do
# do whatever you wanna do with the new files.
done

touch ./TIMEFILE
-------------------------------------------------------------------

if you want to include subdirectories as well replace
find ./* -prune -type f -newer ./TIMEFILE
by
find . -type f -newer ./TIMEFILE

The touch command makes sure the file TIMEFILE always has a timestamp of when the last run of your script ended.

The find command will find only find files which have been place in the directory of the timestamp time of TIMEFILE
  #3 (permalink)  
Old 01-31-2007
goodmis goodmis is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 24
Need To Know In Real Time

Thanks SB008,

I need to know in Real Time. I should have mentioned that.

Thanks again for the reply
  #4 (permalink)  
Old 01-31-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by goodmis
Thanks SB008,

I need to know in Real Time. I should have mentioned that.

Thanks again for the reply


Instead of
touch ./TIMEFILE
you use
date > ./TIMEFILE


At the beginning of the script something like:
OLDDATE=`cat ./TIMEFILE`
  #5 (permalink)  
Old 01-31-2007
goodmis goodmis is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 24
Would I Need a Loop

Would I need a loop to check the directory to verify when the file was added?
  #6 (permalink)  
Old 01-31-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
Quote:
Originally Posted by goodmis
I am uploading files that need to be processed prior to uploading. I will put the files in a directory. My question is how can I write an easy process to kick off a script once a file has been added? Is there an easy way to determine if a file has been added to a directory?
Since you are doing the upload, simply invoke the script as you finish the upload.
  #7 (permalink)  
Old 02-01-2007
goodmis goodmis is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 24
I was told to run a cron job every 2 minutes and once it found the file I could have it transfer it. It seems like overkill to have a process running every 2 minutes looking for a file that may be added only once a day.

Thanks to all who answered
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0