## Thursday, November 10, 2011

### ed is the standard text editor

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