Websitetemplate.org

Welcome > Linux > Miscellaneous > Script Changes to a System

Script Changes to a System

# cp oldfile changedfile
# vi changedfile
--- edit file ---
# diff -e oldfile changedfile > edscr 
# echo w >> edscr 
--- move edscr to target system ---
# ed oldfile < edscr 
# diff oldfile changedfile

See: http://www.linuxdevcenter.com/pub/a/linux/lpt/33_06.html

I've used the above technique when scripting changes to a file. I make the desired change, run the "diff -e", then build a here document. For example:

cd /etc
cp -p logrotate.conf logrotate.conf.orig
ed logrotate.conf <<EOF 21c
    rotate 8
.
5,6c
# keep 8 weeks worth of backlogs
rotate 8
.
w
EOF

Remember, I edited the logrotate.conf file first to get the diff. This technique allows me to script a build, or make modifications to large numbers of servers with a simple script.



Content Copyright 2003-2014 George Toft