LoginSignup
10
8

More than 5 years have passed since last update.

sed でファイルを更新しつつ変更内容を表示する

Posted at

sed で変更した内容を diff -u に流して tee で標準エラーに出力しつつ path にパイプします。

sed -r '
    /^#*PermitRootLogin /cPermitRootLogin without-password
    /^#*UseDNS /cUseDNS no
  ' /etc/ssh/sshd_config |
  diff -u /etc/ssh/sshd_config - |
  tee /dev/stderr |
  patch /etc/ssh/sshd_config

次のように変更内容が Unified 形式の diff で出力されつつ patch で適用されます。

--- /etc/ssh/sshd_config    2015-10-06 14:19:17.090000000 +0000
+++ -   2016-02-06 08:11:40.487720319 +0000
@@ -46,7 +46,7 @@
 # Authentication:

 #LoginGraceTime 2m
-#PermitRootLogin yes
+PermitRootLogin without-password
 #StrictModes yes
 #MaxAuthTries 6
 #MaxSessions 10
@@ -126,7 +126,7 @@
 #ClientAliveInterval 0
 #ClientAliveCountMax 3
 #ShowPatchLevel no
-#UseDNS yes
+UseDNS no
 #PidFile /var/run/sshd.pid
 #MaxStartups 10:30:100
 #PermitTunnel no
patching file /etc/ssh/sshd_config
10
8
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
10
8