Cron job that checks for new/recent files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron job that checks for new/recent files
# 1  
Old 11-10-2016
Cron job that checks for new/recent files

I'm new to shell scripting, and I want to set up a cron job that scans the date/time stamp of all files in a directory, and then if any file is, say, less than 10 minutes old, I want it to execute a command on that file. What would be the best way to go about this? Thanks.

Not sure if it makes a difference, but I'm using Ubuntu 16.04, bash shell.
# 2  
Old 11-10-2016
Welcome DavidHoffman,

I have a few to questions pose in response first:-
  • What have you tried so far?
  • What output/errors do you get?
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.

I would suggest creating a marker file that is already 10 minutes old (look at the touch command) and then use find with the -newer flag to look for files newer than your marker file.

I could, of course, just give you an answer but it is better for you to explore and learn a little. Let us know how you get on and if you get stuck we can help further.



Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. UNIX for Advanced & Expert Users

cron job to extact lines from files to another file and ftp to new server

i have a text file in this format: which creates a new one everyday in the form of filename _zing__r200_2012_8_10_log.txt Fri Aug 10 07:29:17 EDT 2012, usera(192.168.0.245) to anotheruser: hey top, this is a private test Fri Aug 10 07:29:28 EDT 2012, anotheruser(192.168.0.245) to usera: got... (2 Replies)
Discussion started by: bkkid
2 Replies

5. Shell Programming and Scripting

Script that will be a cron job to export rrd files for cacti server

I wrote a quick little script that will eventually end up as a cron job to export rrd files for my cacti server. Here is the script: #!/bin/bash rm -rf /backup/cacti_xml/* cd /var/www/html/rra ls -1 *.rrd | awk '{print "rrdtool dump "$1" > /backup/cacti_xml/"$1".xml"}' | sh -x Is there... (5 Replies)
Discussion started by: TheBigAmbulance
5 Replies

6. UNIX for Dummies Questions & Answers

Cron job to delete files

Hi everyone! I'm sorry, I'm a total noob but would really appreciate any advice or help. I want to create a cron job that would run every hour and would look inside a few different folders. If any new files were created within those folders within the last hour they would be destroyed, but any... (2 Replies)
Discussion started by: jessn
2 Replies

7. UNIX for Dummies Questions & Answers

Cron Job Config files

Hi All, I have created 2 shell scripts and set Cron jobs which runs it at various frequencies.The first one which runs every 2 minutes Monday to Friday and another cron job runs at 11PM on the last Sunday of every month. I have given the cron job entries below. Was wondering whether instead... (5 Replies)
Discussion started by: valluvan
5 Replies

8. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

9. UNIX for Dummies Questions & Answers

CRON usage for CRON job

can anybody explain the usage of CRON for adding a cron job. please provide an example also for better understanding !!! Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies

10. Shell Programming and Scripting

CRON-Job / Shell-Skript deleting special files

Just I'm trying to find script, which will do the following job: 1. as a CRON-Job it shoult a) delete files which will be either older than 24 hours or b) all files within a) a directory deleting recursive b) only a special directory. 2. write an error-/Delete_log... (9 Replies)
Discussion started by: ManfredWL
9 Replies
Login or Register to Ask a Question