LoginSignup
0
0

More than 5 years have passed since last update.

High Sierra にて crontab の編集エディターを nano から vim に変更する方法について

Last updated at Posted at 2018-06-09

概要

Ruby にてスクレイピングを定期的に実施したいと考えたため、cron をセットしようとしました。
crontab -e にて編集しようとすると、見慣れない nano エディタが起動して、非常にわかりずらい。
それで vim をエディターにしたいと思いました。

方法

下記の設定することで実現できました。

bashrc/zshrc

How to specify nano or vim as editor for crontab file
https://www.garron.me/en/bits/specify-editor-crontab-file.html

How to save and exit crontab -e?
https://serverfault.com/questions/308085/how-to-save-and-exit-crontab-e

export VISUAL=vim;
# 不要? nano が editor になって後述の vimrc の設定が不要になる気がしていましたが、そうでもないみたいです。
export EDITOR=nano;

vimrc 2018/6/16 追記

vimrc に下記を追加します。

set backupskip=/private/tmp/*

設定はこのページ を参考にさせていただきました。
詳細は このページ に記載されていました。

原因としては上にある様に、本来crontabがコピーしてきたものが Vimによって名前を変えられ、同じ名前のものとし> て新しいファイルを作るので、 所有者などのファイルのプロパティが変わってしまい正しく処理出来なくなります。

vim で :help crontab でヘルプを見ると、vim のバックアップ機能により crontab のコピーが作成されるとオリジナルが廃棄されるが、 private/tmp に、crontab.xxxxxx が保存されるが、crontab のシンボリックリンクにあるオーナー情報などと食い違ってしまう、というような説明になっているようでした。

When a copy is made, the original file is truncated and then filled
with the new text. This means that protection bits, owner and
symbolic links of the original file are unmodified. The backup file
however, is a new file, owned by the user who edited the file. The
group of the backup is set to the group of the original file. If this
fails, the protection bits for the group are made the same as for
others.

それを避けるために、/private/tmp 配下のバックアップは作りませんよ、、と。
どうもありがとうございました!

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