LoginSignup
115
77

More than 3 years have passed since last update.

危険な crontab -r を封印する

Last updated at Posted at 2013-03-29

cronの設定するときcrontab -eって使うよね?でもこれ結構危険なんです。キーボードのeの隣にあるr、これを間違えてcrontab -rなんてやってしまったら目も当てられない。何の警告もなしにいきなりcrontabの設定が全部消えちゃうんです!

怖いですねー。実際のところは過去何百回とcrontab -eを打ってきたけどこの打ち間違えはしたことがない。でも今日までは大丈夫でも明日やってしまうかもしれない…、そんな不安を少しでも拭えればと最近は bashrc に以下の設定をしています。

~/.bashrc
# crontab -r を封印する
function crontab() {
  local opt
  for opt in "$@"; do
    if [[ $opt == -r ]]; then
      echo 'crontab -r is sealed!'
      return 1
    fi
  done
  command crontab "$@"
}

bashrcの変更を反映させます。

source ~/.bashrc

これで間違えてcrontab -rを実行しちゃっても大丈夫です。

$ crontab -r
crontab -r is sealed!
115
77
1

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
115
77