Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if launchd has started the script?

Tags:

launchd

I configured the launchd to start a command at 18pm every day on my mac pro,but it was not working.

I want to check if the launchd has run the command. I tried the system console, found no anything valuable.

my mac os version is mac os x 10.8.3

My plist file:

<?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>mytask</string>     <key>Program</key>     <string>/opt/local/bin/node</string>     <key>ProgramArguments</key>     <array>         <string>/Users/xxx/My/task.js</string>     </array>     <key>StartCalendarInterval</key>     <dict>         <key>Hour</key>         <integer>18</integer>         <key>Minute</key>         <integer>0</integer>     </dict>     <key>StandardOutPath</key>     <string>/Users/xxx/launchd.stdout.log</string>     <key>StandardErrorPath</key>     <string>/Users/xxx/launchd.stderr.log</string> </dict> </plist> 
like image 377
hywl51 Avatar asked May 23 '13 06:05

hywl51


People also ask

What is Launchctl command?

Launchctl supports taking subcommands on the command-line, interactively, or even redirected from standard input. Adversaries use launchctl to execute commands and programs as Launch Agents or Launch Daemons. Common subcommands include: launchctl load , launchctl unload , and launchctl start .

What is Launchd in IOS?

The launchd process is used by macOS to manage daemons and agents, and you can use it to run your shell scripts. You don't interact with launchd directly; instead you use the launchctl command to load or unload launchd daemons and agents.

What is Launch Agent Mac?

Mac LaunchAgents start when a user logs in. Unlike daemons, they can access the user interface and display information. For example, a calendar app can monitor the user's calendar account for events and notify you when the event occurs.


1 Answers

You defined StartCalendarInterval, so the job has been executed when it was loaded and it will be executed every day at 18:00.

Query launchd(8) to find out its exit status:

launchctl list | grep mytask 

this will return a line line this:

<pid> <status> mytask 

When pid is a number, the job is currently running. Otherwise have a look at status, which is the exit code of the program, node in your case. An exit code of 0 means either that the program was finished successfully or that is has not been started yet. Positive numbers are returned for program errors, while negative ones mean that the job has terminated due to a signal.

I assume the job failed. You may want to check the programs standard output/error. Specify StandardOutPath and StandardErrorPath to do that. The content of these files will likely tell you why the program failed.

like image 125
LCC Avatar answered Oct 16 '22 18:10

LCC