LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-11-2004, 01:51 AM   #1
philipina
Member
 
Registered: May 2003
Posts: 77

Rep: Reputation: 15
Change parameter of /etc/sysconfig/network with a script


Hello,

I'm a newbie in linux and I'm trying to make a script to change the hostname PC.
I get the hostname in $1.
My question are :

By using a script

1) How can I set this value in /etc/sysconfig/network "HOSTNAME=..."

2) How can I add this hostname in /etc/hosts
"127.0.0.1 localhost.localdomain localhost ..."

Thanks in advance for your help.

A.
 
Old 03-11-2004, 03:07 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,288

Rep: Reputation: 174Reputation: 174
Gosh, I can think of a million!


# into .new files just in case

cat network | sed "s/\(HOSTNAME=\).*/\1$1/" > network.new
cat hosts | sed "s/127.0.0.1.*/127.0.0.1 localhost <etc> $1/" > hosts.new


or use 'm4' (great tool)

put a macro placeholder in the files like:

================
HOSTNAME=MACRO_NAME
127.0.0.1 localhost.localdomain localhost MACRO_NAME
==================
then

m4 -DMACRO_NAME=blahblah infile > outfile


or use perl, or tcl etc..


but why?



billy
 
Old 03-11-2004, 04:12 AM   #3
philipina
Member
 
Registered: May 2003
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks a lot it works fine.

I don't understand your question "Why?"
This is simply to change to PC name with a script and I also have to modify "/etc/hosts" to make the link with the new hostname and localhost (127.0.0.1).

Thanks again.

Regards.
 
Old 03-11-2004, 05:05 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,288

Rep: Reputation: 174Reputation: 174
the sed, means:

s/first/second/ # substitute first for second

\(this bit\) # remember this bit and put in \1

s//\1/ # put remebered bit here.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change /etc/sysconfig/network-scripts/ifcfg-eth0 ariana Linux - Networking 1 05-01-2005 01:37 PM
How to change library parameter? blachan Linux - Newbie 0 07-12-2004 06:16 AM
Change parameter of /etc/sysconfig/network with a script philipina Linux - Hardware 1 03-11-2004 12:59 PM
How to change parameter values of a function in shell script? Bassam Programming 0 01-25-2004 09:52 AM
/etc/sysconfig/network ssrikant Linux - Software 1 05-18-2003 03:30 PM


All times are GMT -5. The time now is 09:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration