在OS X上通过crontab执行Node.JS脚本
问题说明
我一直试图弄清楚如何在Mac OS X上使用crontabs.我编写了一个节点脚本,希望能够按计划执行.这是我在crontab文件中使用的行.
I have been trying to figure out how to use crontabs on my mac OS X I have a node script written that I would like to be able to execute in a scheduled manner. Here is the line I am using in my crontab file.
30 * * * * /usr/local/bin/node /Users/pmanca/Google Drive/JavaScript/code/Peter/marketing-tests/testBackup.js
它似乎没有执行.谁能看到我做错了吗?在Mac或Linux服务器上还有另一种方法可以完成我所寻找的吗?您是否还可以在Linux中对crontab作业使用同一行(除了需要更改的文件路径)?
It doesn't appear to be executing though. Can anyone see what I am doing wrong? Also is there another way on a mac or linux server to accomplish what I'm looking for? Also can you use the same line for a crontab job in linux as well(besides the file paths needing to change)?
正确答案
您可以使用两个npm软件包之一,议程
You can use one of the two npm packages, cron or agenda
两者都可以在linux和OS X上工作.如果您的任务是轻量级的并且不需要将作业持久保存到db中,那么Cron最好.议程使用mongodb进行持久化.
Both work on linux and OS X. Cron is best if your tasks are lightweight and you don't need your jobs to be persisted into db. Agenda uses mongodb for persistence.
您可以在cron中将作业配置为:
You can configure a job in cron as:
var CronJob = require('cron').CronJob;
var job = new CronJob({
cronTime: '00 */30 * * * *',
onTick: function() {
/*
* Runs every 30 minutes, every hour, every day, all week
*/
},
start: false,
timeZone: 'America/Los_Angeles'
});
job.start();
要在服务器上后台运行,可以使用永远运行
To run in background on server you can run it with forever
记住cron在左侧还有第6个位置,保持秒数.否则语法是相同的.
Remember cron has an additional 6th place to the left for seconds. Otherwise the syntax is same.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfgabk
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22