43 lines
973 B
Bash
43 lines
973 B
Bash
#!/bin/bash
|
|
|
|
# Scripts checks whether 'testfile' has been modified and prints result
|
|
|
|
# File 'last_change' contains last saved modification date-time of 'testfile'
|
|
# and gets updated if 'stat testfile' shows a different modification date
|
|
|
|
# stdin stdout stderr
|
|
|
|
DIR=`dirname $0` > /dev/null
|
|
pushd $DIR > /dev/null
|
|
|
|
# file 'testfile' not a regular file? exit with error
|
|
if [ ! -f testfile ]
|
|
then
|
|
echo "Datei nicht gefunden"
|
|
echo "Ende mit Fehlercode 1"
|
|
popd > /dev/null
|
|
exit 1
|
|
fi
|
|
|
|
# File 'testfile' found
|
|
# get 'testfile' modified date-time
|
|
modified=`stat testfile | grep -i modi | awk -F' ' '{ print $2 " " $3 }'`
|
|
|
|
# get date-time from change before
|
|
last_modified=`cat last_change`
|
|
# ` Backtick
|
|
|
|
# if both date-time equal no change!
|
|
if [ "$modified" == "$last_modified" ]
|
|
then
|
|
echo "Datei nicht modifiziert!"
|
|
else
|
|
# not equal: file changed
|
|
echo "Datei modifiziert!"
|
|
# save last modified
|
|
echo "$modified" > last_change
|
|
fi
|
|
|
|
popd > /dev/null
|
|
exit 0
|