Mac上定时运行脚本工具--launchctl
2024-08-27 06:23:08
在Mac上可以像在Linux上一样,使用crontab来定时运行脚本,但苹果并不推荐这个方法。苹果推荐使用Launchctl来完成定时任务。
首先,我们先写一个可执行的脚本,列子为php脚本,名字为test.php.
其次,要到相对应的目录下面建立plist文件。
一共有5个文件夹,差别在于,Agents文件夹下的plist是需要用户登录后,才会加载的,而Daemons文件夹下得plist是只要开机,可以不用登录就会被加载
然后,我们编写plist文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.ryan.test</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/php</string>
<string>/Users/Ryan/Zend/workspaces/DefaultWorkspace/test/test.php</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>StandardErrorPath</key>
<string>/Users/Ryan/Documents/test_log/stderr</string>
<key>StandardOutPath</key>
<string>/Users/Ryan/Documents/test_log/stdout</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer></integer>
<key>Minute</key>
<integer></integer>
</dict>
</dict>
</plist>
最后,我们需要load写好的plist文件
launchctl load -w /Library/Daemons/com.ryan.test.plist // 加载
launchctl unload -w /Library/Daemons/com.ryan.test.plist // 卸载
参考文档地址:http://launchd.info
工具地址:http://www.soma-zone.com/LaunchControl/
最新文章
- Android 2016新技术
- 【循序渐进学Python】7.面向对象的核心——类型(上)
- AFNetworking请求中含有中文时程序崩溃
- splay入门
- nodejs配置与入门
- ASP连接MYSQL数据库
- Spring 初学 1
- Android TextView中实现点击文本超链接(无下划线)的封装类
- linux 系统下配置安装 java jdk 图文流程
- ffmpeg h265
- docker - 容器里安装ssh
- IBM Minus One 简单字符处理
- bzoj4904 [Ctsc2017]最长上升子序列
- Nginx反向代理、负载均衡、动静分离、缓存、压缩、防盗链、跨域访问
- 利用 SPICE 分析理解心电图前端中的右腿驱动
- python下载安装BeautifulSoup库
- solr源码分析之数据导入DataImporter追溯。
- 如何构建日均千万PV Web站点(二) 之~缓存为王~
- python pytest测试框架介绍二
- Spring扩展:Spring的IoC容器(注入对象的方式和编码方式)