2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Macで定期的にジョブを実行する

Last updated at Posted at 2019-08-31

MacOSでもcronジョブは実行できるようですが、launchdの使用が推奨されているようです。
簡単に方法のみまとめておきます。
こちらの記事を参考にさせていただきました。

plistファイルを用意する

エディタで下記の内容を記載して適当に保存します。
毎週日曜日の朝8時にTimeMachineバックアップを作成するという内容です。
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>Label</key>
     <string>Weekly Backup</string>
     <key>ProgramArguments</key>
     <array>
          <string>/usr/bin/tmutil</string>
          <string>startbackup</string>
     </array>
     <key>StartCalendarInterval</key>
     <dict>
          <key>Weekday</key>
          <integer>0</integer>
          <key>Hour</key>
          <integer>8</integer>
	  <key>Minute</key>
          <integer>0</integer>
     </dict>
</dict>
</plist>

plistを登録する

下記のコマンドでplistを登録します。

sudo launchctl load /Library/LaunchDaemons/timemachine.weekly.plist

登録されているかはsudo launchctl listコマンドで確認します。
本稿の内容で設定した場合、実行結果に「Weekly Backup」の行が出力されれば登録済みとなります。

以上で設定は完了です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?