Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting Question

Status
Not open for further replies.

dial8d

Technical User
Feb 6, 2006
80
GB
Ok, I have found a solution to this, but it looks a little ugly, so i thought id see if you guys can come up with something more elegant.

Im creating a first boot script resource for use with NIM automated installs. I want the fb_script to do lots of things, but the part i have been puzzling with is how to get it to edit the /etc/rc.tcpip file on the newly installed AIX server.

For example, xntpd is by default disabled in /etc/rc.tcpip, and i want the fb_script to enable it by removing the leading #.

Code:
# Start up Network Time Protocol (NTP) daemon
#start /usr/sbin/xntpd "$src_running"

My 1st thought was to use sed, and i come up with this, which does work, but looks pretty ugly.

Code:
sed '/xntpd/s/^\#start \/usr\/sbin\/xntpd \"\$src_running\"/start \/usr\/sbin\/xntpd \"\$src_running\"/' /etc/rc.tcpip

A colleague came up with something a little shorter.

Code:
cat /etc/rc.tcpip | sed "s/#\(start.*xntpd.*\)/\1/" | grep xntpd

Im sure there are a million ways this can be done, so I thought id open this up for discussion.



 
how about appending the line to the end of the file?
 
yes, i did think about doing that. I guess theres no real reason not to do it like that, other than i thought it would be nice to retain the original format of the file.

I guess im just picky ! :)
 
[tt]echo "/\/usr\/sbin\/xntpd\ns/^#//\nw\nq"|ed /etc/rc.tcpip[/tt]

or

[tt]echo "/\/usr\/sbin\/xntpd
s/^#//
w
q"|ed /etc/rc.tcpip[/tt]

The echo provides 4 ed commands in order to edit the file:
search for xntpd line
substitute initial "#" with empty string
write
quit


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top