Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a Cron job for Node.js

Tags:

node.js

unix

cron

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?

like image 950
murvinlai Avatar asked Feb 03 '11 23:02

murvinlai


People also ask

How do I run a cron job in node?

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.

What does cron 0 * * * * * mean?

*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.

What is crontab JavaScript?

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 .


1 Answers

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.

like image 193
murvinlai Avatar answered Oct 21 '22 20:10

murvinlai