When I do bad things, I tried to construct an unfriendly world (Linux) to be reported immediately <Prequel>

In the first part, when you do"bad things I think"with the vim editor, I will show you how to create an inexhaustible world to be reported.
(In this case, reporting = log output, but actions can be changed as appropriate.)

** 2018/09/29 Update:
In order to record logs only when editing is added, we made the following corrections.
· Save file hash value to environment variable when opening file with vim
· Report only when the hash value at file open is different from the hashed value after editing **

Material

vim Editor configuration file (/etc/vimrc)

Shell script

The bad things I think

Edit history file
- Edit the command history is"bury the mistake in the dark"bad thing

Edit the log file
- Editing the log file is"to falsify the facts"Bad

How to create a world that is not easy

1. Put a trap in the vim editor

Add the setting below to the end of the vim editor's configuration file (/etc/vimrc).
The shell script (watchvim.sh) will now be executed ** when editing the file **.
Pass the file name (<afile>) you are editing, the hash value of the file (\$PREHASH), and the user name (\$USER) as arguments.

Also, in preparation for users using the vi editor, register vim with syntax highlight turned off as vi's alias.
(** It is not only to notice that you are using the vim editor, but also to give consideration to users who do not want to use syntax highlighting **)

/etc/profile.d/force_vim.sh

# Force users to use vim instead of vialias vi="vim -c ':syntax off'"

2. Put a shell script to log output when a specific file is edited

First of all, I will create a placement place

mkdir /etc/vimrc.d

Place the following shell script (watchvim.sh) and configuration file (watchvim.conf) in/etc/vimrc.d/.

# Created by watchvim.sh
# This is the watchvim.sh configuration file.
# watchvim.sh watches only the files you specify with absolute path below and logger who edits them.
# when they are edited with Vim.
/var/log/*
*bash_history

This will also remain in the log as perfectly.
The realization of the unfriendly world has come closer and closer.

A postcard

By writing the file name to the setting file (watchvim.conf), you can set the monitoring target freely. Wild cards can also be used.
If you are interested, please try using it.

~~ ※ Please note that when you execute": w"with the vim editor, it will judge that it was edited even if not editing anything in the specification · · ·. ~~
** * Fixed to be notified only when edit is added in 2018/09/29 update **

In the second part, we introduce the mechanism of change detection using shell script.
I think that polishing will take place in a world that is not easy because it is a mechanism that detects whether it is a vim editor or a sed command anyway after editing.

** Thank you very much for your continued reading until the end.
We are looking for ways to create a gentle world, so if you have recommendations on how to make it, please let me know! **