Sep 272017
 

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

Share
Oct 042016
 

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.

Share
Jun 182015
 

I recently had to verify a whole bunch of servers were responding to SNMP and had the correct DNS reverse look ups in Active Directory.
I used this little script so that it would ask me for an IP address and then do a ping, and then if a server was reachable over ICMP, a nslookup if a server responded to the SNMP Query for the system name.
Continue reading »

Share
Nov 142013
 

I wanted to rename a whole bunch of models to transform their names into all lowercase with just the hostname rather than the FQDN.
I used this script to do it with bash and vnmsh. The script will loop through all models found by the query with a model type handle, and then renames then with a vnmsh update command.


#!/bin/bash
export CLIMNAMEWIDTH=70
OldIFS=$IFS
IFS=$'\n'
WORKPATH="/opt/CA/Spectrum/vnmsh"

$WORKPATH/connect

## Pingable
MDLLIST=`$WORKPATH/show models mth=0x10290`
MDLLIST=`echo "$MDLLIST" | grep -vi mname`

for x in $MDLLIST; do
MDLHANDLE=`echo $x | awk -F '[ |.]+' ' { print $1 } '`
MDLNAME=`echo $x | awk -F '[ |.]+' ' { print tolower($2) }'`
echo $MDLHANDLE
echo $MDLNAME

$WORKPATH/update mh=$MDLHANDLE attr=0x1006e,val=$MDLNAME
done
$WORKPATH/disconnect
IFS=$OldIFS

Share
Mar 012013
 

One of my headless wireless devices have been freezing lately, and since it’s in a somewhat isolated location, I have no idea when it freezes.
So I wrote up a quick script to check to see whether it’s up and I’m running it every hour so that it alerts me when it goes down. It will also alert me once it comes back up, in case it comes back up by itself !

The script will also save the last state that the device was in so that it will only email me once when the device goes down.


#!/bin/bash
email=YOUR@EMAIL.HERE

ip=$1
if [[ -z $1 ]]; then
echo Usage: ./pingcheck.sh \
exit
fi
if [ ! -f /tmp/$1.status ]; then
touch /tmp/$1.status
fi

oldstatus=`cat /tmp/$1.status`
reply=`ping -c 1 $ip | grep 64\ bytes | wc -l`
echo $reply > /tmp/$1.status

if [[ $oldstatus -ne $reply ]]; then
if [[ $reply -eq 1 ]]; then
echo $1 is online | mail -s "Node is online" $email
else
echo $1 is offline | mail -s "Node is offline" $email
fi
fi

Share