ed is the standard text editor

Posted on November 10, 2011 by Tommy McGuire
Labels: system administration, shell, tip

Yes, I know there are other ways of doing this kind of thing, particularly if you have chef or cfengine or whatever configured. Right here, right now, I don't. Yay.

ed has one very strong advantage over other editors: it is scriptable. No, not scriptable as in you can write code to modify how it works, scriptable as in it can be driven by a file full of commands, and thus can be run remotely, in a loop. So, if you need to edit a file on a mess of machines, to make the same change everywhere, remember, "ed is the standard text editor."

Create a script file containing the ed commands and the appropriate text:

$ cat /tmp/edit 
g/^SSLRandomSeed connect/
a

# http://www.g-loaded.eu/2011/09/27/mod_gnutls-rc4-cipher-beast/
SSLHonorCipherOrder on
SSLCipherSuite !aNULL:!eNULL:!EXPORT:!DSS:!DES:RC4-SHA:RC4-MD5:ALL
.
w
q
$

Then, use ssh to connect to the remote host and run the ed command on the file to be edited, reading standard input from the file. Trust me, using the separate file is easier than writing the commands in a here-document or something.

$ for j in 01 02; do for k in b c; do ssh host$k$j ed /usr/local/httpd/conf/httpd.conf < /tmp/edit; done; done
active directory applied formal logic ashurbanipal authentication books c c++ comics conference continuations coq data structure digital humanities Dijkstra eclipse virgo electronics emacs goodreads haskell http java job Knuth ldap link linux lisp math naming nimrod notation OpenAM osgi parsing pony programming language protocols python quote R random REST ruby rust SAML scala scheme shell software development system administration theory tip toy problems unix vmware yeti
Member of The Internet Defense League
Site proudly generated by Hakyll.