#!/bin/bash # # ---------------------------------------------------------------------- # # Description: Issue a warning when it is time to run a file system check # # Author: Maccus # # Initial version: 111228-01 # # This script has been written and tested on # Ubuntu Linux 10.04 and Debian Testing (Wheezy) # # ---------------------------------------------------------------------- # # Usage: Place the script in "/usr/local/bin", do a # # "chmod +x /usr/local/bin/system-fsckmsg" # # Then, add the script as a starter in your session management. # Or create a file with the following content to ~/.config/autostart/system-fsckmsg # # [Desktop Entry] # Name=File system check # Name[nl]=Bestandssysteemcontrole # Comment=Notify about pending file system checks... # Comment[nl]=Melding over bestandsysteem controle... # Type=Application # Icon=terminal # Terminal=true # Exec=system-fsckmsg # # ---------------------------------------------------------------------- # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ---------------------------------------------------------------------- # # Uncomment for debugging # # set -x # Start script echo -e "\n\033[1;33mSTATUS\033[0m: Script \"$(basename $0)\" is gestart...\n" for CONF in "/etc/scriptconfig/system-common.conf" \ ; do if [ -f "${CONF}" ]; then . "${CONF}" else echo -e "\033[1;31mFOUT\033[0m: $0: Configuratiebestand \"${CONF}\" werd niet gevonden! Script wordt beeindigd..." sleep 2 exit fi done # Alleen EXT partities # Niet de quotes voor egrep vergeten! PARTS="`df -T | egrep "(ext2|ext3|ext4)" | cut -d " " -f 1`" for PART in ${PARTS}; do # Partitiegrootte PSIZE="$( df "${PART}" | grep "${PART}" | sed "s|${PART}[ ]*||" | cut -d " " -f 1 )" # Mount count MNTCOUNT="$( /sbin/tune2fs -l ${PART} | grep "^Mount" | sed "s|.*count:[ ]*||" )" MAXCOUNT="$( /sbin/tune2fs -l ${PART} | grep "^Maximum" | sed "s|.*count:[ ]*||" )" DIFFCOUNT="$( expr ${MAXCOUNT} - ${MNTCOUNT})" # Vind alleen partities groter dan 10GB #if [ "${PSIZE}" -gt "10240000" -a "${DIFFCOUNT}" -lt "4" -a "${MAXCOUNT}" != "0" -a "${MAXCOUNT}" != "-1" ]; then if [ "${DIFFCOUNT}" -lt "5" -a "${MAXCOUNT}" != "0" -a "${MAXCOUNT}" != "-1" ]; then LABEL="$( /sbin/e2label ${PART} )" LABELS="$(echo ${LABELS} [${LABEL:=$PART}] | sed "s|[ ]$||")" DEVICES="$(echo ${DEVICES} ${PART} | sed "s|[ ]$||")" [ "${DIFFCOUNT}" -le "0" ] && HRDIFFCOUNT="volgende" [ "${DIFFCOUNT}" = "1" ] && HRDIFFCOUNT="tweede" [ "${DIFFCOUNT}" = "2" ] && HRDIFFCOUNT="derde" [ "${DIFFCOUNT}" = "3" ] && HRDIFFCOUNT="vierde" [ "${DIFFCOUNT}" = "4" ] && HRDIFFCOUNT="vijfde" if [ -z "${DISKMSG01}" ]; then DISKMSG01="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG01}" elif [ -z "${DISKMSG02}" ]; then DISKMSG02="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG02}" elif [ -z "${DISKMSG03}" ]; then DISKMSG03="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG03}" elif [ -z "${DISKMSG04}" ]; then DISKMSG04="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG04}" elif [ -z "${DISKMSG05}" ]; then DISKMSG05="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG05}" elif [ -z "${DISKMSG06}" ]; then DISKMSG06="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG06}" elif [ -z "${DISKMSG07}" ]; then DISKMSG07="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG07}" elif [ -z "${DISKMSG08}" ]; then DISKMSG08="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG08}" elif [ -z "${DISKMSG09}" ]; then DISKMSG09="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG09}" elif [ -z "${DISKMSG10}" ]; then DISKMSG10="[${LABEL}] zal tijdens de ${HRDIFFCOUNT} herstart worden gecontroleerd..." DISKMSG="${DISKMSG}\n${DISKMSG10}" fi fi done # Quotes niet vergeten! if [ -n "${LABELS}" ]; then echo -en "SYSTEEMBERICHT: Automatische bestandssysteemcontrole van harde schijf partitie(s) zal worden uitgevoerd: ${DISKMSG} Je kunt de bestandssysteemcontrole(s) uitstellen door de \"mount count\" te verlagen met 1. Mount count verlagen met 1 ? Typ ja of nee: " read YESNO if [ "${YESNO}" = "ja" ]; then echo for DEVICE in ${DEVICES}; do MNTCOUNT="$( /sbin/tune2fs -l ${DEVICE} | grep "^Mount" | sed "s|.*count:[ ]*||" )" NEWCOUNT="$( expr ${MNTCOUNT} - 1 )" LABEL="$( /sbin/e2label ${DEVICE} )" /sbin/tune2fs -C ${NEWCOUNT} ${DEVICE} echo -e "Mount count van [${LABEL:=$DEVICE}] met 1 verlaagd van ${MNTCOUNT} naar ${NEWCOUNT}...\n" done else echo -e "\nOm een bestandssysteemcontrole te forceren kun je een Terminal openen en \"sudo shutdown -Fr now\" invoeren. De computer zal dan herstarten en ALLE harde schijf partities gaan controleren. Afhankelijk van de grootte van de schijven kan dit enige tijd duren. Een schijf van 1TB heeft ongeveer een half uur nodig. Zorg ervoor dat alle toepassingen zijn afgesloten voordat je het shutdown commando uitvoert." echo -en "\nWil je nu herstarten en de controles automatisch uitvoeren? (sluit je openstaande toepassingen!) Typ ja of nee: " read YESNO if [ "${YESNO}" = "ja" ]; then # Datumstempel for HOMEDIR in ${HOMES[@]}; do [ -d "${HOMEDIR}" ] && echo "$(date +%d-%m-%Y)" > "${HOMEDIR}/.system-fsckmsg" done sleep 2 sudo shutdown -Fr now else echo -e "\nControles worden nu niet uitgevoerd. Je kunt op een later tijdstip de controles uitvoeren." fi fi echo -e "\n\033[1;33mSTATUS\033[0m: Klaar...Toets enter om dit script te beeindigen..." read fi exit 0