I have a NodeJS script that deletes old records based on time, when the script run it takes all records from date x to date y and deleted them, if I'll re-run this script again right ways, it'll say: "no records found for deletion" etc.
The script exposed as an NPM script for easy usage, it defined in my package.json like that:
{
...
"scripts": {
"deleteOldRecords": "cd server && cross-env NODE_ENV=prod node scripts/deleteOldRecords.js"
}
...
}
I want this the NPM to be run every 3 minutes, so I defined it in the crontab
like that:
*/3 * * * * cd /my/project && npm run deleteOldRecords > /dev/null 2>&1
Now, I'm checking /var/log/syslog
and I do see an output that says the job has run OK:
Jun 4 20:39:01 localhost CRON[19497]: (node-user) CMD (cd /my/project && npm run deleteOldRecords > /dev/null 2>&1)
The problem is that it does not perform the real action and when I run it again manually form te console:
node-user@ip-0-0-0-0:/$ cd /my/project && npm run deleteOldRecords > /dev/null 2>&1
It's finding records for deletion and delete them successfully which should works like that because the crontab running should delete them and the manual running should say "no records found for deletion" as i mentioned above.
Any idea why it happened?