I have a cron job that call a shell script.
*/2 * * * * sh cron_test.sh >> output.log
In side the shell script, I run some command lines like:
#!/usr/bin
./mongo/bin/mongodump .....
FILE_NAME='abc'
node mynode.js $FILENAME
It runs if I just call cron_test.sh in command prompt. However, it doesn't run node if it is run by cronjob. It does run the mongodump command. So, what's wrong? is there anything I have to set for permission, etc?
Scheduling a Simple Task with node-cron Input the following code into the index. js file to create our simple task scheduler: const cron = require("node-cron"); const express = require("express"); const app = express(); cron.
*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.
Cron is a tool that allows you to execute something on a schedule. This is typically done using the cron syntax. We allow you to execute a function whenever your scheduled job triggers. We also allow you to execute a job external to the javascript process using child_process .
thanks.. I find it out..
either I need to specify the node path or do that in the sh script:
nodejs/node myscript.js
where nodejs/node is where the node installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With