0
0

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.

Macでcronにdateコマンドの結果を使いたくてハマった話。

Posted at

こんにちは、ひらきちです。

時々、cronで実行したいプログラムの引数で、
dateコマンドの実行結果(例えば今日の日付(2024/04/09など))
を与えたいことって、ありますよね?

これがなかなかうまくいかない!!
なんかいつもハマる!

今日も例によって、Macでハマりました。
備忘録的にメモとしてQiitaに記事を残しておきます。

Macでcronにコマンドの実行結果を使いたい場合

35 11 * * * python hoge.py "$(date -v-1d +\%Y/\%m/\%d)"

(参考)Linuxでcronにコマンドの実行結果を使いたい場合

35 11 * * * python hoge.py `date -d "1 day ago" +%Y/%m/%d`

悩んだ軌跡

  • Linux系だとバッククオーテーションを使うと、コマンドの実行結果を引数に使える
  • でもMacでは許容されなくて、ハマってしまった(MacはFreeBSD系(Unix系)ということでLinuxとはちょっと違うらしい)
  • そこで(流行りの)chatGPT 3.5に6回ほど質問して解決できました
  • しかし、chatGPTも平気で嘘をつく(ハルシネーション)ので、何度も質問することに
  • 解決できてよかった(笑)

参考記事

まぁ次は同じことに出会ったら、
サクッと片付けられれば良いなぁと思いながら、
この記事を閉めます。

以上!

0
0
3

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?