作業前の設定ファイルのバックアップなど。CentOS 7, CentOS 8でテスト済み。
バックアップスクリプト
sudo tee /usr/local/bin/backup << 'EOF'
#!/bin/bash
PATH=/usr/bin:/bin
LANG=ja_JP.UTF-8
if [[ ${#} -ne 1 ]]; then
echo "Usage: ${0} file or directory"
exit 1
fi
if [[ ! -f "${1}" && ! -d "${1}" ]]; then
echo "${0}: No such file or directory"
exit 2
fi
TARGET=$(echo "${1}" | sed -e 's/\/$//')
\cp -a "${TARGET}" "${TARGET}.$(date '+%Y%m%d%H%M%S')"
if [[ ${?} -ne 0 ]]; then
echo "${0}: failed" >&2
exit 3
fi
exit 0
EOF
sudo chmod 755 /usr/local/bin/backup
sudoで/usr/local/binを使えるようにする
sudo /usr/local/bin/backup /etc/sudoers sudo sed -i -e '/^Defaults secure_path.*/s/^/#/' /etc/sudoers
