summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrina Gómez <irinagomez@us.es>2020-03-03 10:40:05 +0100
committerIrina Gómez <irinagomez@us.es>2020-03-03 10:40:05 +0100
commit0c0ba58bd101038870c796aabc355b13a03ff5e3 (patch)
tree9f285c9285220c95c3410a29504f3c4e3ac77911
parentb897e4ea2857a797d5e66318b84fc8a6941f8198 (diff)
#488 #959 comparedhcpopengnsys: Fixes error when computer definition was in one line.
-rwxr-xr-xserver/bin/comparedhcpopengnsys35
1 files changed, 29 insertions, 6 deletions
diff --git a/server/bin/comparedhcpopengnsys b/server/bin/comparedhcpopengnsys
index 3f661253..e6fdd3b1 100755
--- a/server/bin/comparedhcpopengnsys
+++ b/server/bin/comparedhcpopengnsys
@@ -32,12 +32,35 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1
source $SERVERCONF 2> /dev/null || raiseError access "Fichero de configuración del servidor"
trap "rm -f $TMP_DHCP $TMP_MYSQL" 1 2 3 9 15
-# Creo fichero temporal del dhcp
-grep -v "#" $DHCPFILE |egrep -e "host " -e "hardware ethernet" -e fixed-address | sed -e 's/.$//' \
- | sed -e s/"^.*host[[:space:]]*"//g -e s/\{/\;/g -e s/"^.*hardware ethernet[[:space:]]*"/=/g -e s/"^.*fixed-address[[:space:]]*"/=/g \
- | sed -e :a -e '$!N;s/\n=/ \;/;ta' -e 'P;D'\
- | sed -e s/\ //g -e s/://g -e s/\;$//g -e s/\;\;/\;/g |sort > $TMP_DHCP
-
+# Genero fichero temporal de dhcp recorriendo la configuración del dhcp cadena a cadena.
+# Quito comentarios del fichero
+CONTENIDO=$(sed 's/#.*$//' $DHCPFILE)
+OLDLINE=""
+HOST=""
+IP=""
+MAC=""
+for LINE in ${CONTENIDO} ; do
+ case $LINE in
+ "host") OLDLINE="host" && continue ;;
+ "hardware") OLDLINE="hardware" && continue ;;
+ "ethernet") [ "$OLDLINE" == "hardware" ] && OLDLINE="hardware ethernet" && continue ;;
+ "fixed-address") OLDLINE="fixed-address" && continue ;;
+ "}") [ "$HOST" == "" ] || echo "$HOST;${MAC%%;};${IP%%;}" >> $TMP_DHCP
+ HOST=""
+ IP=""
+ MAC=""
+ continue
+ ;;
+ esac
+ case "$OLDLINE" in
+ "host") HOST=$LINE ;;
+ "hardware ethernet") MAC=$(echo $LINE|sed s/://g) ;;
+ "fixed-address") IP=$LINE ;;
+ esac
+ OLDLINE=""
+done
+# Ordeno el fichero
+sort -o $TMP_DHCP $TMP_DHCP
# Creo fichero temporal del mysql, de la base de datos de opengnsys
dbexec "select CONCAT_WS (';', nombreordenador, mac, ip) from ordenadores order by nombreordenador;" > $TMP_MYSQL