Project

General

Profile

Download (1.3 KB) Statistics
| Branch: | Tag: | Revision:

fuss-fucc / utils / gen-computerList.sh @ master

1 5a0c8155 Marco Marinello
#!/bin/bash
2
3
IMAGE="fuss9-64bit-2019-08-07-16-img"
4
LENOVO_IMAGE="001-ThincCentre-500gb-20190801-img"
5
JOIN="join"
6
DB="/var/lib/octofuss/octofuss.db"
7
8
rm -f list.txt
9
touch list.txt
10
11
PCS=$(sqlite3 $DB <<EOF
12
select distinct hostname from client_component;
13
.quit
14
EOF
15
)
16
17
for fqdn in $PCS; do
18
        client=$(echo $fqdn | cut -d '.' -f 1)
19
        # Check if the host has already been mapped
20
        if ! grep $client list.txt 2>&1 > /dev/null; then
21
                # Find that MAC
22
                MAC=$(sqlite3 $DB <<EOF
23
select value from client_component where hostname = "$fqdn" and component like "mac%";
24
.quit
25
EOF
26
)
27
                MAC=$(echo $MAC|cut -d ' ' -f 1)
28
                VENDOR=$(sqlite3 $DB <<EOF
29
select value from client_component where hostname = "$fqdn" and component like "system_vendor";
30
.quit
31
EOF
32
)
33
		VENDOR=$(echo $VENDOR | cut -d ' ' -f 1)
34
                if [ -z "$MAC" ] ; then
35
                        echo No mac for $fqdn
36
                else
37
			if ! grep $MAC list.txt 2>&1 > /dev/null ; then
38
				THIS="$IMAGE"
39
				if [ "$VENDOR" = "LENOVO" ] ; then
40
					THIS="$LENOVO_IMAGE"
41
				fi
42
	                        echo $client $MAC $THIS $JOIN $(grep $client /etc/clusters | head -1 | cut -d ' ' -f 1) >> list.txt
43
			else
44
				echo "$MAC has more than one fqdn ($fqdn)"
45
			fi
46
                fi
47
        fi
48
done