0
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 1 year has passed since last update.

【cron】PATHの設定方法

Posted at

設定方法

crontabでPATH定義

crontabファイルの中で、PATHを以下のように定義できます。

crontab
PATH=/usr/bin:/bin:/opt/homebrew/bin
* * * * * コマンド

以下のように記述しても$PATHは展開されません。

crontab
PATH=$PATH:/opt/homebrew/bin
* * * * * コマンド

bashコマンドなどに-lオプションを付与

bashコマンドやzshコマンドに-lオプションを付けることでログインシェルとして実行できます。

crontab
* * * * * bash -l -c "コマンド"
* * * * * bash -l ファイルパス

ただし-lでログインシェルとして実行する機能のあるシェル以外では使用できません。

なおshebangでも上記と同様のことが実現できます。

sample.sh
#!/bin/bash -l

0
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
0
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?