Home Backup drive check and GPU/disk temperature
« Home »
Jun 3rd, 2012 Comments Off on Backup drive check and GPU/disk temperature

Backup drive check and GPU/disk temperature

I thought to share here some of the bash scripts I’ve made for maintaining my Gentoo Linux system.

1. Checking for a correct detachable drive before backing up with rsync.

In my case, the script checks whether the correct eSATA backup drive is mounted before doing the actual backup. It first checks whether there are anything mounted on /mnt/esata, and tries to mount a drive if possible; a failure produces an error message. If a drive is found, it checks the UUID of the drive to confirm that the drive is really a correct one, to prevent accidental loss of data.

You can find the UUID of your drive in /dev/disk/by-uuid/


if ! grep -q /mnt/esata /proc/mounts ; then
    if ! mount /mnt/esata ; then
        echo "\033[1;31m*\033[0m Backup drive 'BackupOne' is not present."
        exit 1

DRIVELETTER=`cat /proc/mounts | grep /mnt/esata | cut -f 1 -d ' '`
DRIVEUUID=`ls -l /dev/disk/by-uuid/ | grep ${DRIVELETTER/\/dev\//} | awk '{ print $9 }'`
DRIVEUSAGE=`df -h | grep ${DRIVELETTER} | awk '{ print $5 }'`

if [ ! ${DRIVEUUID} = 735aa2fb-4022-4f41-80c7-4977e51aa967 ] ; then
    echo -e "\033[1;31m*\033[0m Wrong drive mounted in /mnt/esata: ${DRIVEUUID}"
    exit 1

echo -e "\033[1;32m*\033[0m Backup drive 'BackupOne', UUID=${DRIVEUUID},"
echo -e "\033[1;32m*\033[0m is present and mounted as ${DRIVELETTER}, ${DRIVEUSAGE} used."
echo -e "\033[1;32m*\033[0m Commencing rsync..."

rsync /what/ever/you/want/to/sync

NOTE: I have the corresponding line in /etc/fstab:

UUID=735aa2fb-4022-4f41-80c7-4977e51aa967 /mnt/esata ext3 noatime,users 0 1

2. Getting GPU and drive temperatures to a file.

This may seem somewhat complicated… I have four internal drives with SMART-compatible temperature sensors (sdb to sde, sda is a Compact Flash card). A cron job first reads the temperature of the ATI GPU, using

/opt/bin/aticonfig --od-gettemperature

and writes it on an intermediary file /tmp/atitemperature. The cron job then runs this script which reads the temperatures of the four internal drives and the two (possibly) mounted external drives, and writes these to the other intermediary file /tmp/temperature, which, when ready, is then added to the end of /var/log/temperature.log, which in turn is read by root-tail and displayed on the screen. The reason for those stupid intermediary files is the occasional unpredictable delays in reading the temperatures, which caused the output to flicker and jump around.

The checkremovable() function checks whether the removable drive exists and has SMART capability (i.e. if not, it is an USB thumb drive).

# Check the temperatures of display adapter and hard drives.

checkremovable() {
    if [ -b $1 ]; then
        # Check whether it is a proper hard drive or an USB Flash drive
        SDFTEMP=`/usr/sbin/hddtemp -q -f /usr/share/hddtemp/hddgentoo.db SATA:$1 2>&1`
        if [ -n $"`echo $SDFTEMP | grep "no sensor"`" ]; then
            /usr/sbin/hddtemp -q $1 >> /tmp/temperature
            echo $SDFTEMP >> /tmp/temperature
        echo "$1: not present" >> /tmp/temperature

sleep 5
cat /tmp/atitemperature | grep -A 1 "HD 46" > /tmp/temperature
/usr/sbin/hddtemp -f /usr/share/hddtemp/hddgentoo.db SATA:/dev/sdb >> /tmp/temperature
/usr/sbin/hddtemp -f /usr/share/hddtemp/hddgentoo.db SATA:/dev/sdc >> /tmp/temperature
/usr/sbin/hddtemp -f /usr/share/hddtemp/hddgentoo.db SATA:/dev/sdd >> /tmp/temperature
/usr/sbin/hddtemp -f /usr/share/hddtemp/hddgentoo.db SATA:/dev/sde >> /tmp/temperature
checkremovable /dev/sdf
checkremovable /dev/sdg

cat /tmp/temperature >> /var/log/temperature.log

Comments are closed.

Return to Top ▲Return to Top ▲