I needed to get all MAC addresses without hyphens today so I could match against some MAC Address barcodes.
Ended up writing this one-liner to get what I needed. I’ve added some variables to make it a bit easier to read here.
$svrDHCP = "DHCP Server"
$scope = "10.10.0.0"
Get-DhcpServerv4Lease -ComputerName $svrDHCP -scope $scope | select IPAddress,ClientID,Hostname | ForEach-Object { Add-Member -InputObject $_ -name Mac -MemberType NoteProperty -Value $($_.clientID -replace "-",""); write-output $_} | out-gridview
I wrote a little snippet to update my PXE server’s Debian netboot image so I can schedule this to run every month or so to ensure that my Netboot image is up to date.
The variables are to set the Debian mirror, architecture, and paths and filenames for the downloaded image file, and where the image file should be un-tarred to.
I have architecture in there because I had some old machines which require i386 kernels. If you don’t need i386, then you can replace all the arch
variables and hardcode amd64
instead.
#!/bin/bash
debmirror=http://mirror.internode.on.net/pub/debian
arch=amd64
tmpfile=/tmp/$arch-netboot.tar.gz
tftppath=/srv/tftp/deb-stable/$arch
wget $debmirror/dists/stable/main/installer-$arch/current/images/netboot/netboot.tar.gz -O $tmppath
tar -C $tftppath -xzf $tmpfile ./debian-installer/amd64/initrd.gz ./debian-installer/amd64/linux --strip-components=3
I had a RAID6 array die on my recently so I wanted to start running SMART tests across all the drives that were in the RAID6 array.
This was easy for me as the RAID drives were all Seagates, so I used the following snippet to do it:
for x in /dev/sd?; do
output=$(smartctl -i $x);
if [[ $output =~ 'Seagate' ]]; then
smartctl -t long $x;
fi;
done
The snippet above checks the SMART information for the string ‘Seagate’, and if it finds it, then starts the SMART test via smartctl.
Then to monitor the progress of the SMART tests, I used the following snippet:
while true; do
clear
for x in $(
for x in /dev/sd?; do
output=$(smartctl -i $x);
if [[ $output =~ 'Seagate' ]]; then
echo $x;
fi;
done); do
echo $x
smartctl -l selftest $x
done
sleep 10
done
This snippet has a nested for statement so that it only shows the self test logs for the drives that are Seagates.
I wanted to build a menu item in Zabbix to open a ticket against a host in Zabbix so that we could flag one for attention.
Continue reading »