So I have following problem. I want to create script, which creates action (in this example, appropriate entry in log'd be enough), after metadata of file /bin/a is changed. I am checking metadata by parsing stat output. After that, script is using sed to take new value of metadata and I want my script to continue.
The problem is, that even if it has correct value of new time stamp in "Change" parameter from stat (new value for file /bin/a, in which for example, I have changed chmod to 754), it still produces error to the log (basically takes what is in "else" instead of what is under "if"... I hope I made myself clear enough :) Here is the script:
#!/bin/bash
# These lines do nothing more
# then logging STDOUT and STDERR to the log file:
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/var/log/rest-nscd.log 2>&1
# Script itself:
while true
do
sleep 5
CHANGE=$(stat /bin/a |grep Change |awk '{print $3}')
if [ "$CHANGE" == "22:03:09.499223862" ]; then
echo "OK === $(date)"
else sed -i "s/22:03:09.499223862/$(stat /bin/a |grep Change |awk '{print $3}')/g" /bin/reset-test.sh && echo "NOT OK" '!!!!!!'
fi
done
Aucun commentaire:
Enregistrer un commentaire