Last active
April 26, 2017 02:11
-
-
Save clamytoe/c33e296fe0d084be4bf287ef4ceb93c0 to your computer and use it in GitHub Desktop.
Script to get the serial number from the host and the monitor of our Unix machines at work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
XORG=${1:-/var/log/Xorg.0.log} | |
HOSTNAME=`hostname -s` | |
SYSSERIAL=`sudo /usr/sbin/dmidecode -s system-serial-number` | |
#SHORTSERIAL=${SYSSERIAL%% *} | |
/usr/bin/awk -F": " ' | |
BEGIN { | |
sys="'${HOSTNAME}'"; | |
sysserial="'${SYSSERIAL}'"; | |
} | |
$2 ~ "Monitor name" { | |
mon=$3; | |
namerec=NR; | |
} | |
$2 ~ "Serial No" { | |
if (NR == (namerec +1)) | |
monserial=$3; | |
} | |
END { | |
printf ("%s:%s,%s:%s\n",sys,sysserial,mon,monserial); | |
exit; | |
}' $XORG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe Devin Teske was the original author, not sure though.