MAC小技巧--定时任务清理内存

一、编写plist文件 com.xxxxxx.xxxx.plist文件 ,把这个文件丢到/Library/LaunchAgents下

<?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>Label</key>
    <string>com.laboratory.sh.schedule.clean.pc</string>
    <!-- 要运行的程序 路径 -->
    <key>Program</key>
    <string>/Users/lucky/Documents/Laboratory/sh_file/schedule/clean/clean_pc_by_purge.sh</string>
    <!-- 运行间隔,与StartCalenderInterval使用其一,单位为秒s -->
    <key>StartInterval</key>
    <integer>300</integer>
    <!-- 标准输入文件 -->
    <key>StandardInPath</key>
    <string>/Users/lucky/Documents/Laboratory/sh_file/schedule/clean/run-in.log</string>
    <!-- 标准输出文件 -->
    <key>StandardOutPath</key>
    <string>/Users/lucky/Documents/Laboratory/sh_file/schedule/clean/run-out.log</string>
    <!-- 标准错误输出文件 -->
    <key>StandardErrorPath</key>
    <string>/Users/lucky/Documents/Laboratory/sh_file/schedule/clean/run-err.log</string>
  </dict>  
</plist>

二、编写清理脚本

!/bin/bash
sudo purge 
#文件路径,不需要日志可以吧日志注释掉
echo "clean pc success by use commond purge at :"+`date "+%Y/%m/%d %X"` >> /Users/lucky/Documents/Laboratory/sh_file/schedule/clean 

三、运行

#/Library/LaunchAgents/com.laboratory.sh.schedule.clean.pc.plist
#加载plist文件
launchctl load   /Library/LaunchAgents/com.laboratory.sh.schedule.clean.pc.plist
#查看列表
launchctl list | grep 'schedule'

四、工程文件

clean_pc_by_purge.sh
com.laboratory.sh.schedule.clean.pc.plist
load_clean_schedule.sh
start_clean_schedule.sh
stop_clean_schedule.sh
unload_clean_schedule.sh
run-err.log
run-in.log
run-out.log

参阅:
https://my.oschina.net/gavinnie/blog/776181

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容