<div dir="auto">sed -i -e 'edit #1' -e 'edit #2' ... -e 'edit #n’ <div dir="auto"><br></div><div dir="auto">The edits happen in sequence per line.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mar 19, 2017 12:46 AM, "Raj Wurttemberg" <<a href="mailto:rajaw@c64.us">rajaw@c64.us</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey Phil,<br>
<br>
Can't say that I even knew that sed could do multiple replacements in one<br>
line. :) (I've only been scripting with bash for about two years... I'm a<br>
noob) I just Googled it and came up with this...<br>
<br>
Is this kind of what you are talking about? (I've never used mktemp either)<br>
<br>
TMPIPCFG=$(mktemp /etc/sysconfig/network-<wbr>scripts/tmpipcfg.XXXX)<br>
sed -i 's/IPADDR=.*/IPADDR=<a href="http://1.2.3.4/" rel="noreferrer" target="_blank">1.2.3.4/</a>; s/BROADCAST=.*/BROADCAST=<a href="http://1.2.3.0/" rel="noreferrer" target="_blank">1.2.<wbr>3.0/</a>;<br>
s/GATEWAY=.*/GATEWAY=<a href="http://1.2.3.1/" rel="noreferrer" target="_blank">1.2.3.1/</a>' $TMPIPCFG<br>
mv $TMPIPCFG /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0<br>
<br>
Learned something new tonight...<br>
<br>
Thanks!<br>
/Raj<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a> [mailto:<a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a>] On Behalf Of Phil<br>
Turmel<br>
Sent: Saturday, March 18, 2017 9:56 PM<br>
To: <a href="mailto:ale@ale.org">ale@ale.org</a><br>
Subject: Re: [ale] Update ifcfg-eth0 file from command line? (need to re-ip<br>
50 servers)<br>
<br>
Aaaaahhhhhhgggg!<br>
<br>
Raj, Leam, y'all making me cringe with those procedures. For pity's sake,<br>
use mktemp to safely make an empty temp file in the *same* folder, stream<br>
from the original to the temp file with *one* instance of sed, then 'mv' the<br>
temp file back over the original. At no point will you have a partially<br>
configured network -- filesystems are required to guarantee that renaming<br>
over file atomically replaces it. And at no point will you have an unsecure<br>
temp file exposed.<br>
<br>
Phil<br>
<br>
On 03/18/2017 09:03 PM, Raj Wurttemberg wrote:<br>
> Yeah, I was actually going to do a sed to just replace the old values and<br>
do most everything in one step:<br>
><br>
> sed -i 's/IPADDR=.*/IPADDR=<a href="http://1.2.3.4/" rel="noreferrer" target="_blank">1.2.3.4/</a>'<br>
> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0 2> /dev/null sed -i<br>
> 's/BROADCAST=.*/BROADCAST=<a href="http://1.2.3.0/" rel="noreferrer" target="_blank">1.2.<wbr>3.0/</a>'<br>
> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0 2> /dev/null sed -i<br>
> 's/GATEWAY=.*/GATEWAY=<a href="http://1.2.3.1/" rel="noreferrer" target="_blank">1.2.3.1/</a><wbr>'<br>
> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0 2> /dev/null<br>
><br>
> haha... yes, I noticed a long time ago that the RHEL tries to use any file<br>
in the /etc/sysconfig/network-scripts directory! Doh!<br>
><br>
> Thanks,<br>
> /Raj<br>
><br>
><br>
> -----Original Message-----<br>
> From: <a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a> [mailto:<a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a>] On Behalf Of<br>
> Leam Hall<br>
> Sent: Saturday, March 18, 2017 8:32 PM<br>
> To: Atlanta Linux Enthusiasts <<a href="mailto:ale@ale.org">ale@ale.org</a>><br>
> Subject: Re: [ale] Update ifcfg-eth0 file from command line? (need to<br>
> re-ip 50 servers)<br>
><br>
> Untested, and I tend to do things in multiple steps.<br>
><br>
> cp /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0 /tmp<br>
><br>
> cat /tmp/ifcfg-eth0 | egrep -iv "ipaddr|broadcast|gateway" ><br>
> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0<br>
><br>
> echo "IPADDR=1.2.3.4" >> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0<br>
> echo "BROADCAST=1.2.3.0" >> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0<br>
> echo "GATEWAY=1.2.3.1" >> /etc/sysconfig/network-<wbr>scripts/ifcfg-eth0<br>
><br>
> service network restart<br>
<br>
______________________________<wbr>_________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo</a><br>
<br>
______________________________<wbr>_________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo</a><br>
</blockquote></div></div>