macOS 使用 crontab 定时任务

在 macOS 中使用 cron 定时任务和 Linux 下略有区别。

首先在终端输入,查看服务是否运行:

sudo launchctl list | grep cron

输出结果:

-	0	com.vix.cron

接下来查看启动项的配置:

locate com.vix.cron

 

如果提示 database 不存在

WARNING: The locate database /var/db/locate.database does not exist.
To create the database, run the following command:

  sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.

 

按照上面的英文提示,创建一个 database,等几分钟后才会生成相关文件:

$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
$ locate com.vix.cron
/System/Library/LaunchDaemons/com.vix.cron.plist

 

随后可以使用 crontab -e 创建任务,具体方法参考:https://javascript.net.cn/articles/690

修改时间 2024-05-12

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
JavaScript 工作者线程
WordPress 自定义模板路径
MySQL 数据库中货币单位如何存储
HTML 对话框元素 dialog
Node.js test 模块
Node.js path 模块
JavaScript Global 对象
WordPress 常用函数 / sanitize_user