sed を他のコマンドと組み合わせて、リモートサーバーで実行します。おそらく、複数のサーバーを管理しているときに便利です。
scp
ローカルの環境から、リモートにsedファイルを転送。IPアドレスは存在しえない数です。
$ scp ntp.sed azureuser@12.345.67.890:/home/azureuser/
ssh でリモート環境でコマンドを実行
-t
がリモートでコマンドを実行するオプション
ssh -t azureuser@12.345.67.890 sed -i.bak -f /home/azureuser/ntp.sed /home/azureuser/ntp.conf
結果
リモートで実行したのと同じになる。ちなみに下記のログはsedコマンドで、実IPを書き換えてみた。
$ ssh azureuser@12.355.67.890
Enter passphrase for key '/Users/ushio/.ssh/id_rsa':
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-1040-azure x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
5 packages can be updated.
0 updates are security updates.
New release '18.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Mon Apr 1 02:08:51 2019 from 12.345.67.890
azureuser@tsuyoshis:~$ ls
drivers employees ntp.conf ntp.conf.bak ntp.sed parsecsv.sh test words
azureuser@tsuyoshis:~$ cat ntp.conf
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server ntp.example.com prefer
pool ntp.ubuntu.com
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery