Hi Bernard,

I've just faced a small bug when imaging a host:

if /var/lib/systemimager/scripts/hosts file contains more than one line for a 
specific ip address, the imaging fails because /tmp/variables.txt contains 
HOSTNAME=<1st hostname occurence>
<2nd hostname occurence read as shell command>
<3rd...>
DONAMINNAMES=...

thus when variables.txt is run, it fails whith command not found "<2nd 
hostname>"

I've attached a patch that should optimize and fix this issue.

The best (instead of a tail -1) should be to check if result is more than one 
line long and stop there with appropriate message stating that hosts file has 
duplicate entries.

BTW if HOSTNAME contains a FQDN hostname, then the simplified hostname is 
easily obtained using shell variable ${HOSTNAME%%.*}
Using that instead of |sed 's/\..*$//g' could avoid forking a sed process.

Best regards.

-- 
   Olivier LAHAYE
   Responsable calcul scientifique
   CEA DRT/LIST
   +33 1 69 08 13 25

--- ./initrd_source/skel/etc/init.d/functions.orig	2011-05-17 16:05:54.655134385 +0200
+++ ./initrd_source/skel/etc/init.d/functions	2011-05-17 16:13:56.887134036 +0200
@@ -1193,24 +1193,23 @@
         logmsg "Searching for this machine's hostname in $FILE by IP: $IPADDR"
         
         # Command summary by line:
-        # 1: convert tabs to spaces -- contains a literal tab: <ctrl>+<v> then <tab>
+        # 1: get line with IP address from host file (no more no less)
         # 2: remove comments
-        # 3: add a space at the beginning of every line
-        # 4: get line with IP address (no more no less)
-        # 5: strip out ip address
-        # 6: strip out space(s) before first hostname on line
-        # 7: remove any aliases on line
-        # 8: remove domain name, leaving naught but the hostname, naked as the day it were born
+        # 3: convert tabs to spaces -- contains a literal tab: <ctrl>+<v> then <tab>
+        # 4: strip out ip address
+        # 5: strip out space(s) before first hostname on line
+        # 6: remove any aliases on line
+        # 7: remove domain name, leaving naught but the hostname, naked as the day it were born
         
         HOSTNAME=`
-            sed 's/[[:space:]]/ /g' $FILE | \
-            grep -v '^ *#' | \
-            sed 's/^/ /' | \
-            grep " $IPADDR_ESCAPED " | \
-            sed 's/ [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*//' | \
-            sed 's/ *//' | \
-            sed 's/ .*//' | \
-            sed 's/\..*$//g'
+            grep "$IPADDR_ESCAPED " $FILE | \
+            grep -v '^*#' | \
+            sed -e 's/[[:space:]]/ /g' \
+                -e 's/ [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*//' \
+                -e 's/ *//' \
+                -e 's/ .*//' \
+                -e 's/\..*$//g' | \
+                tail -1
         `
     else
         logmsg "No hosts file."
------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
sisuite-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sisuite-users

Reply via email to