shell脚本应该放在哪里?
大家好计算机人员:)
我有一个 shell 脚本,我将用它作为看门狗计时器。它检查我的其他“主”程序是否正在运行。如果不是,则会重新启动它。
问题是:如何在 Mac 上安装它?是否存在文件夹/plist 文件场景,操作系统将自动并定期调用脚本,确保我的程序永远不会运行那么长时间?理想情况下,我希望每分钟都测试一次,但每小时甚至一天几次也足够了。
谢谢你!
Hello fellow computer people :)
I have a shell script that I will use as a watchdog timer. It checks to see if my other 'main' program is running. If it is not, it restarts it.
The question is: How do I get this installed on a Mac? Is there a folder/plist file scenario somewhere where the OS will automatically and periodically call the script, ensuring that my program never goes that long without running? I would ideally like to test every minute, but every hour or even a couple of times a day would be satisfactory.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Mac OS X 上执行此操作的方法是使用启动服务。它取代了旧的系统服务,例如
init
和crontab
,并提供了一个用于管理系统服务的单一、统一的框架。就您而言,您可能不需要单独的脚本 - 保持应用程序实例的运行应该由系统处理。首先,您需要创建描述您的守护程序/脚本/应用程序的 .plist 文件。您可以将其放置在以下位置之一,具体取决于服务类型:
~/Library/LaunchAgents
:由用户提供的每用户代理。/Library/LaunchAgents
:管理员提供的每用户代理。/Library/LaunchDaemons
:由管理员提供的系统范围的守护进程。/System/Library/LaunchAgents
:Mac OS X 每用户代理。/System/Library/LaunchDaemons
:Mac OS X 系统范围的守护进程。定义服务后,您可以使用
launchctl
命令来控制launchd
。例如,您可以列出正在运行的服务、启动/停止服务等。完整文档位于:
launchd
守护进程和代理The way to do this on Mac OS X is using Launch Services. It replaces the older system services such as
init
andcrontab
and provides a single, unified framework for managing system services.In your case, you probably don't need a separate script - keeping an instance of your app running should be handled by the system. First you need to create
.plist
file that describes your daemon/script/application. You place it in one of the following locations, depending on the type of service:~/Library/LaunchAgents
: Per-user agents provided by the user./Library/LaunchAgents
: Per-user agents provided by the administrator./Library/LaunchDaemons
: System wide daemons provided by the administrator./System/Library/LaunchAgents
: Mac OS X Per-user agents./System/Library/LaunchDaemons
: Mac OS X System wide daemons.Once you have defined the service, you can use the
launchctl
command to controllaunchd
. For example, you can list running services, start/stop services, and so on.The full documentation is here:
launchd
Daemons and Agents我不是 Mac 用户,但应该有 cron 守护进程。 http://hints.macworld.com/article.php?story=2001020700163714
I'm not a Mac user but there should be
cron
daemon. http://hints.macworld.com/article.php?story=2001020700163714Crontab 应该可以很好地帮助你。将脚本设置为每 X 分钟运行一次,然后 cron 将完成剩下的工作。如果您更喜欢 GUI 界面的程序,请尝试 cronnix。
Crontab should do you nicely. Set your script to run every X minutes and cron will do the rest. If you prefer a GUI interface to your programs, try cronnix.