# Very Basic shell script problem - beginner alert...

**URL:** <https://forums.suse.com/t/very-basic-shell-script-problem-beginner-alert/21639>\
**Category:** SLES Install-Boot\
**Created:** [January 26, 2012, 8:26pm UTC](https://forums.suse.com/t/very-basic-shell-script-problem-beginner-alert/21639 "2012-01-26T20:26:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![System1](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@System1](https://forums.suse.com/u/System1)\
**Post date:** [January 26, 2012, 8:26pm UTC](https://forums.suse.com/t/very-basic-shell-script-problem-beginner-alert/21639/1 "2012-01-26T20:26:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [January 28, 2012, 12:06am UTC](https://forums.suse.com/t/very-basic-shell-script-problem-beginner-alert/21639/2 "2012-01-28T00:06:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [January 28, 2012, 1:46am UTC](https://forums.suse.com/t/very-basic-shell-script-problem-beginner-alert/21639/3 "2012-01-28T01:46:02Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [February 1, 2012, 5:26pm UTC](https://forums.suse.com/t/very-basic-shell-script-problem-beginner-alert/21639/4 "2012-02-01T17:26:02Z")

</div>

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](https://http)  
wget [http://[smthost]/repo/tivoli/TIVsm-API64.i386.rpm](https://http)  
wget [http://[smthost]/repo/tivoli/TIVsm-API.i386.rpm](https://http)  
wget [http://[smthost]/gskssl32-8.0.14.6.linux.x86.rpm](https://http)  
wget [http://[smthost]/repo/tivoli/gskcrypt32-8.0.14.6.linux.x86.rpm](https://http)  
wget [http://[smthost]/repo/tivoli/gskssl64-8.0.14.6.linux.x86\_64.rpm](https://http)  
wget [http://[smthost]/repo/tivoli/gskcrypt64-8.0.14.6.linux.x86\_64.rpm](https://http)

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

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

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

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