Skip to content

Instantly share code, notes, and snippets.

@bilashcse
Last active October 18, 2016 09:36
Show Gist options
  • Save bilashcse/5b970e74843edd6004bfb10040a089b9 to your computer and use it in GitHub Desktop.
Save bilashcse/5b970e74843edd6004bfb10040a089b9 to your computer and use it in GitHub Desktop.
A Node.js script to remove all images of a directory which are more then 6 hours older using NodeJs child process
var CronJob = require('cron').CronJob;
var exec = require('child_process').exec;
var path = '../tmp/uploads';
var job = new CronJob({
cronTime: '*/59 * * * *',
onTick: function() {
exec('find '+path+' -mmin +359 -type f -name "*.*" -exec rm -f {} +', function(err,stdout,stderr){
if(err)
console.log(err);
});
},
start: false,
timeZone: 'Asia/Dhaka'
});
job.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment