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
populate)


<hosts_entry>
<host_address>192.168.1.1</host_address>

hostname
hostname.somedomain.com

</hosts_entry>

is

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
Full-Qualified-Hostname

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

jimc’s Profile: http://forums.novell.com/member.php?userid=6130
View this thread: http://forums.novell.com/showthread.php?t=451394

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


jimc

jimc’s Profile: http://forums.novell.com/member.php?userid=6130
View this thread: http://forums.novell.com/showthread.php?t=451394

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
puzzle?

Cheers,
Willem


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: http://forums.novell.com/member.php?userid=2303
View this thread: http://forums.novell.com/showthread.php?t=451394

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

#!/bin/bash

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-8.0.14.6.linux.x86.rpm
wget http://[smthost]/repo/tivoli/gskcrypt32-8.0.14.6.linux.x86.rpm
wget http://[smthost]/repo/tivoli/gskssl64-8.0.14.6.linux.x86_64.rpm
wget http://[smthost]/repo/tivoli/gskcrypt64-8.0.14.6.linux.x86_64.rpm

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

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-8.0.14.6.linux.x86.rpm
/tmp/gskcrypt32-8.0.14.6.linux.x86.rpm
rpm -U /tmp/gskssl64-8.0.14.6.linux.x86_64.rpm
/tmp/gskcrypt64-8.0.14.6.linux.x86_64.rpm
rpm -U /tmp/TIVsm-API.i386.rpm /tmp/TIVsm-API64.i386.rpm
/tmp/TIVsm-BA.i386.rpm

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

echo “Copying scheduling scripts to /etc/init.d and setting them up as
services.”
cp /tmp/dsmcsched.sh /etc/init.d/dsmc
cp /tmp/dsmcadsched.sh /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
server
#the notification.msg contains text placeholder whereever I want the
server name to appear.

PLACEHOLDER=“placeholder”
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
inspiration.


jimc

jimc’s Profile: http://forums.novell.com/member.php?userid=6130
View this thread: http://forums.novell.com/showthread.php?t=451394