Very Basic shell script problem - beginner alert...

I’m developing a SUSE11/OES11 autoyast installation and have run into a
glitch. I reckon its an easy shell script fix, but my knowledge of shell
scripting is pretty much zero, so please excuse.

The problem I’ve run into is in populating the hosts file after getting
hostname and ip address with ask. I want to get the conventional hosts
file entry with

IP-address Full-Qualified-Hostname Short-hostname

However what I get using autoyast xml like this (using ask to





IP-address Full-Qualified-Hostname

IP-address Short-hostname

and I’m told this is “as designed”.

So at the moment I have a line in /etc/hosts of
IP-address Full-Qualified-Hostname
and in /etc/HOSTNAME just the string

So what I reckon I want to do is to read /etc/HOSTNAME into a variable
parse it into say $FQDN and $HOSTONLY and then use sed to edit
/etc/hosts with s/$FQDN/$FQDN $HOSTONLY/

I’ve got as far as working out I probably need to use awk to do the
parsing, but the syntax of getting the data from /etc/HOSTNAME and
parsing it into the variables is making my brain hurt…

So, how do I do that, or are there any better ideas?


jimc’s Profile:
View this thread:

Solved. I would delete the thread if I could work out how to!


jimc’s Profile:
View this thread:

jimc;2171294 Wrote:[color=blue]

Solved. I would delete the thread if I could work out how to![/color]

No need to delete as others might find this thread useful :slight_smile:

I am curious though, could you elaborate on what you did to solve the


Novell Knowledge Partner (voluntary sysop)

It ain’t anything like Harry Potter… but you gotta love the magic IT
can bring to this world

magic31’s Profile:
View this thread:

OK, maybe it will help someone…
I have a script set to run on the first boot of the system in autoyast,
using this xml…

And this is an extract from the shell script

#we need to edit the hosts file as autoyast won’t do it
#we need to extract hostname from /etc/hosts as the hostname
#enviroment variable seems only to contain LINUX on first boot, not the
server name
#hostnames with spaces will break this
#and serve the perpetrator right

realhostname=$(cat /etc/HOSTNAME | cut -d\. -f1)
realfqdn=$(cat /etc/HOSTNAME)
sed -i ‘s/’$realfqdn’/’$realfqdn’ ‘$realhostname’/g’ /etc/hosts

The firstboot script, combined with the use is proving to be a useful
tool for the way I want to work. What I’m tending to do is set up a
subdir on the smt server for each app I want in post install, together
with a shell script. In the main script I wget the shell script and run
it. For instance the wy I’m installing the Tivoli backup software we use
is with this shell script


cd /tmp

echo “Dowloading installation rpms from susedisto server.”
wget http://[smthost]/repo/tivoli/TIVsm-BA.i386.rpm
wget http://[smthost]/repo/tivoli/TIVsm-API64.i386.rpm
wget http://[smthost]/repo/tivoli/TIVsm-API.i386.rpm
wget http://[smthost]/gskssl32-
wget http://[smthost]/repo/tivoli/gskcrypt32-
wget http://[smthost]/repo/tivoli/gskssl64-
wget http://[smthost]/repo/tivoli/gskcrypt64-

echo “Downloading shell scripts and config files.”
wget http://[smthost]/repo/tivoli/
wget http://[smthost]/repo/tivoli/
wget http://[smthost]/repo/tivoli/

wget http://[smthost]/repo/tivoli/notification.msg

wget http://[smthost]/repo/tivoli/dsm.opt
wget http://[smthost]/repo/tivoli/dsm.sys

chmod 700 *.sh

echo “Installing tivoli rpms.”
rpm -U /tmp/gskssl32-
rpm -U /tmp/gskssl64-
rpm -U /tmp/TIVsm-API.i386.rpm /tmp/TIVsm-API64.i386.rpm

REALHOSTNAME=$(cat /etc/HOSTNAME | cut -d\. -f1)
echo “Creating new dsm.sys with node name $REALHOSTNAME from master
cp /tmp/dsm.sys /opt/tivoli/tsm/client/ba/bin/dsm.sys;
echo "nodename " $REALHOSTNAME >>

echo “Copying scheduling scripts to /etc/init.d and setting them up as
cp /tmp/ /etc/init.d/dsmc
cp /tmp/ /etc/init.d/dsmcad
cp /tmp/dsm.opt /opt/tivoli/tsm/client/ba/bin/dsm.opt

cd /etc/init.d

insserv dsmc
insserv dsmcad

#and now the notification email to the backup admins to set up the
#the notification.msg contains text placeholder whereever I want the
server name to appear.

sed -i ‘s/’$PLACEHOLDER’/’$REALHOSTNAME’/g’ /tmp/notification.msg
sendmail of admins </tmp/notification.msg

echo “”

Now I’m not presenting this as any great model for the best way to do
these things. I’m very much a novice at shell scripts, autoyast and
all the rest of it (but learning fast I hope), and I am very sure
this can be done much better. However it seems to be working for me
and making my life easier. So its presented here simply for


jimc’s Profile:
View this thread: