DrivePolling

Aus Programmers Guide

Version vom 06:37, 2. Nov. 2010 bei Roy (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Script to Check if Disk Status Changes

Run this Script in the Local Crontab:
crontab -e
#*/5 *   * * *   root    bash /etc/backup-platten-polling > /dev/null 2>&1

If the online Status changes, the script create or delete the lock file in /var/lock/

If the lockfile is available, you can Backup Data or use the disk for other work.


#!/bin/bash
 
device="/dev/disk/by-id/"
 
lock="/var/lock/"
platte1="usb-BUFFALO_HD-PXU2_001010070301C5160-0:0-part1"
platte2="usb-BUFFALO_HD-PXU2_0010100703010DD10-0:0-part1"
mailadresse="script@firma.de"
cd $device
 
if ls -l| grep "$platte1">/dev/null
	then
	echo "Platte 1 verbunden"
	cd $lock
	if ls -l|grep "$platte1">/dev/null
		then
		echo "pl 1 nothing to do"
		else
		echo "pl 1 file anlegen"
		echo "Erste Backup-Platte wurde erfolgreich verbunden und die Nacht zum Backup herangezogen." | mail -s "Festplatte 1 verbunden" $mailadresse
		touch "$platte1"
	fi
cd $device
else
	echo "Platte 1 getrennt"
	cd $lock
	if ls -l|grep "$platte1">/dev/null
		then
		echo "pl 1 auswerfen"
                rm "$platte1"
                echo "Erste Backup-Platte wurde getrennt." | mail -s "Festplatte 1 getrennt" $mailadresse
		else
		echo "pl 1 nix zu tun"
	fi
 
cd $device
fi
 
if ls -l| grep "$platte2">/dev/null
	then
	echo "Platte 2 verbunden"
	cd $lock
        if ls -l|grep "$platte2">/dev/null
                then
                echo "pl 2 nothing to do"
                else
                echo "pl 2 file anlegen"
		echo "Zweite Backup-Platte wurde erfolgreich verbunden und die Nacht zum Backup herangezogen." | mail -s "Festplatte 2 verbunden" $mailadresse
                touch "$platte2"
        fi
cd $device
else
	echo "Platte 2 getrennt"
	cd $lock
        if ls -l|grep "$platte2">/dev/null
                then
                echo "pl 2 auswerfen"
                rm "$platte2"
                echo "Zweite Backup-Platte wurde getrennt." | mail -s "Festplatte 2 getrennt" $mailadresse
                else
                echo "pl 2 nix zu tun"
        fi
 
cd $device
fi
 
exit 0
Persönliche Werkzeuge