|
Screencast einer Terminalsitzung in der die Besonderheiten der Zeitstempel atime, mtime und ctime für Verzeichnisse demonstriert werden. URL: http://vimeo.com/9822634 Directory-Timestamps in Linux-Dateisystemen from Ronald Woelfel on Vimeo. Skript zum automatischen Abspielen der gezeigten Kommandos: #!/bin/bash # shellscript to execute a list of shell commands
# with the chance to interfere with own commands VERSION="0.2 Wed Feb 17 18:18:50 CET 2010"
# Copyright (C) 2010 Ronald Woelfel <ronald.woelfel @ netzoffice.de>
# # 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., 675 Mass Ave, Cambridge, MA 02139, USA. # ----------------------------------------------------------------- # comment out, if there are problems with ansi-code sequences
esc=`echo -en "\033"` red="$esc[1;31m" green="$esc[1;32m" blue="$esc[1;34m" norm="$esc[m"
# Shellcommands stored in a array cmd # this is a example to compile nagios, substitute with your # own shell commands cmd=( '# atime, mtime und ctime besitzen für Verzeichnisse eine etwas andere' '# Bedeutung als für Dateien, hier werden die Unterschiede gezeigt.' 'mkdir demo' 'stat demo' 'sleep 2' '# Das Auflisten des Verzeichnisinhaltes mit ls entspricht einem' '# lesenden Zugriff auf eine Datei, die atime ändert sich deshalb.' 'ls demo' 'stat demo' '# Der Verzeichnisinhalt entspricht dem Inhalt einer Datei' '# mtime ändert sich also, wenn z.B. eine Datei hinzukommt.' 'touch demo/a' 'stat demo' '# Bei einer neuen mtime aktualisiert sich auch die ctime.' '# Wie man sieht, gilt dies auch für Verzeichnisse.' '#' '# Unverändert bleibt die Zeitstempel des Verzeichnisses jedoch' '# bei Änderungen der Metadaten der enthaltenen Dateien:' 'chmod 777 demo/a' 'stat demo' '# ' '# Betrachten wir nun noch Änderungen in Unterverzeichnissen von "demo"' 'mkdir demo/unter' 'stat demo' 'touch demo/unter/abc' 'stat demo' '# Wie man sieht bleiben die Zeitstempel von "demo" unberührt.' '#' ) # dont change anything below, unless you know what your are doing
number=${#cmd[*]}
zl=0 # execute shell commands step by step
while [ $zl -lt $number ] do echo -n "${blue}Next: ${norm}" firstchar=${cmd[$zl]:0:1} # If the next command starts wie a comment (#) then # use colour green if test $firstchar = "#" then echo "$green ${cmd[$zl]} ${norm}" zl=`expr $zl + 1` continue else echo "$red ${cmd[$zl]} ${norm}" fi echo -n "${blue}Execute? (y)/n: ${norm} "
read key test -z $key && key="y" if [ $key == "n" ]
then echo "Give alternativ command or just ENTER to do nothing" read usercommand eval $usercommand else eval ${cmd[$zl]} fi zl=`expr $zl + 1` done
|