How to make a script to run everytime a new file is copied into a directory??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make a script to run everytime a new file is copied into a directory??
# 1  
Old 04-15-2009
How to make a script to run everytime a new file is copied into a directory??

Hi folks

I have a unix script script1 in a directory folder1 and also I have few input log files in this directory. My input log files will be copied into this directory folder1 from the portable thumb drive.

Now what I want is I need to run this script1 whenever any new file is copied into this directory and also in a generic way whenever the contents(files) in this folder1 directory changes.

It may look like I can do this with some cron job set to some time intervals everyday, but it will be simply wasting the CPU resources as most of the times I will be running complex scripts other than this script.
The unix environment I am using is cygwin installed in Windows XP.

Thanks in advance..........
# 2  
Old 04-15-2009
Yes as you said you can do with a slight modification in that.

Invoke a find command in crontab for a specified interval, and invoke the script from there if only the directory content has got changed.

Give the path as that directory only, so CPU resources wont get wasted.
This is one way, other ways are also welcome.

Have you got it ?
# 3  
Old 04-15-2009
GNU find supports the -newer option, so you could do this (pseudo code)
Code:
find files with modification time later than reference file
loop over the list
    do whatever you have to do
update reference file

Using this via cron would waste minimal resources if nothing changes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help to make script run recursively

I have this little bash script I use to transcode mkv files using handbrake. #!/bin/bash sourcedir="/media/raid10/video/to_be_encoded_series" destdir="/media/raid10/video/series" cd "$sourcedir" for i in *.mkv; do HandBrakeCLI -i "$i" -o "$destdir/${i%.*}.mkv" -e x264 -q 20.0 -E copy -B... (4 Replies)
Discussion started by: barrydocks
4 Replies

2. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

3. Shell Programming and Scripting

how we can make shell script not to run

Hi,shell script is scheduled from maestro and we want mastero should not run shell script so can we edit the shell script so that it should run.ThanksPrakash (5 Replies)
Discussion started by: prakashdba2010
5 Replies

4. UNIX for Dummies Questions & Answers

Script run everytime a new terminal window is opened

I created a script called title #!/bin/sh echo "^0;$*^G" It will change the terminal window titlebar to what ever I type after the script (title BIG would change titlebar to BIG instead of terminal) Is there a way to make it run so it will work on every terminal window that gets opened.... (1 Reply)
Discussion started by: amason0508
1 Replies

5. UNIX for Dummies Questions & Answers

How do I run a .bin file in another directory in a script?

The way this works from the command prompt is: ___________________________________________ cd /data/local/bin chmod 0755 file.bin ./file.bin _______________________________________________ How do I make this happen in a script. The file must be run in its directory but I can not get the... (2 Replies)
Discussion started by: chrstdvd
2 Replies

6. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

7. UNIX for Dummies Questions & Answers

help to make list of files and run script..

Hey, I have finally made a command that works and now has to run it on 200+ files to run it on. How do I do that? Just fyi and if it complicates anything my commandline is: awk '{if ($1 ~ /1/) print $2}' file (yup, is should print $2 if $1 is a certain value) It doesn't work when I: ... (2 Replies)
Discussion started by: lost
2 Replies

8. Shell Programming and Scripting

Can anyone make this script run faster?

One of our servers runs Solaris 8 and does not have "ls -lh" as a valid command. I wrote the following script to make the ls output easier to read and emulate "ls -lh" functionality. The script works, but it is slow when executed on a directory that contains a large number of files. Can anyone make... (10 Replies)
Discussion started by: shew01
10 Replies

9. UNIX for Dummies Questions & Answers

backing up file everytime script run and saving other backups

how would i go about creatng a backup of a file everytime a script is run so that the next time it is run the old backup gets pushed back and the most recent backup is 1st. (new)backup.1 (old)backup.2 that kind of idea?? (4 Replies)
Discussion started by: knc9233
4 Replies

10. Shell Programming and Scripting

Need to run source .bashrc everytime

hi all, I've included some variables in my .bashrc file. But everytime i'm logging in i need to source my .bashrc file to make effect of my variables. i'm having an account on a highly secured production environment. I've the following in my ~/.bashrc file alias cls=clear How to make... (2 Replies)
Discussion started by: kalyanraj
2 Replies
Login or Register to Ask a Question