引き続き電源が入らないコンピュータでクローンジョブをスケジュールしますか?

引き続き電源が入らないコンピュータでクローンジョブをスケジュールしますか?

毎月1日にスクリプトを実行したいと思います。
コンピュータの電源が切れている場合は、次回コンピュータの電源を入れたときに実行したいと思います。

Anacronは「停電」ユースケースに適していますが、毎日、毎週、毎月の間隔のみを提供します。毎月遅すぎ、毎週早すぎます。

fcronを確認しましたが、そのパッケージがTimeshiftと競合するため、オプションではありません。

私は、cronが毎月1日と4日の間にいつでもタスクを実行できるとしたら、それも大丈夫だと思いました。私はcron構文を見て、これは実際には可能ではないと思いました。

この問題を解決する方法を知っている人はいますか?

私はArch Linux(Manjaro)を使用しています。

ベストアンサー1

このような(未テスト)

#!/bin/bash
# run this via crontab on days 1-4 and @reboot
#
# Store the run_month here, or somewhere writable on disk not /tmp
runfile="$HOME/run_month"
# make sure $runfile exists, initalize to a non-month if 1st run ever 
[[ ! -f "$runfile" ]] && echo "init" >"$runfile"
#
# get the last month we ran
rf="$(cat "$runfile")"
# get the current month
cm="$(date "+%b")"
# if $rf is the same as $cm, quit
if [[ "$cm" = "$rf" ]] ; then
  exit
fi
# Remember we ran this month
echo "$cm" >"$runfile"
#
# Left  as an exercise for the student 

おすすめ記事