Skip to content

Instantly share code, notes, and snippets.

@clamytoe
Last active April 26, 2017 02:11
Show Gist options
  • Save clamytoe/c33e296fe0d084be4bf287ef4ceb93c0 to your computer and use it in GitHub Desktop.
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.
#!/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
@clamytoe
Copy link
Author

I believe Devin Teske was the original author, not sure though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment