blob: a1fd4e3c813414cfe35add77bff725f300f36aea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#/usr/bin/sh
# Startdate: 2021-02-12 10:00
# Dependencies:
# centos8-req: inotify-tools
# Rewritten to handle across nfs because the reference implementation runs this monitor on a nfs client and not the server
# suggested INDIR: /mnt/public/Images/username1-photos/website
test -z "${INDIR}" && export INDIR="${1}"
test -z "${INDIR}" && { echo "Please provide directory name as INDIR or parameter 1. Aborted." 1>&2 ; exit 1 ; }
# CONFIGURE THESE
WATCHFILE="${INDIR}"/updatenow.txt
STOPFILE="${INDIR}"/stop.txt
COMMAND1="ssh server1 \"sudo find ${INDIR} ! -type l \( ! -user user1 -o ! -group usergroup1 \) -exec chown user1.usergroup1 {} \; ; sudo find ${INDIR} ! -type l \( ! -perm /g+r -o ! -perm /g+w \) -exec chmod g+rwX {} \; ;\""
COMMAND2="/mnt/public/Support/Programs/shortcuts/s2s.py --indir ${INDIR} --apply --debug 8 --delete"
LOOPTIMER=5
# the looptimer is so that the program will pause every once in a while to check for the stop file
clean_s2s_inotify() {
rm -f "${STOPFILE}" 1>/dev/null 2>&1
:
}
trap '__ec=$? ; printf " caused s2s-inotify to stop.\n" ; clean_s2s_inotify ; trap "" 2 ; exit ${__ec} ;' 2 # catch CTRL+C
rm -f "${STOPFILE}"
while test ! -f "${STOPFILE}" ; do
oldstat="${stat}"
count="$( inotifywait -e modify -t "${LOOPTIMER}" "${WATCHFILE}" 1>/dev/null 2>&1 ; echo $? )"
stat="$( stat -c "%Y" "${WATCHFILE}" )"
#echo "count=${count}"
#if test ${count} -gt 0 2>/dev/null ;
if test "${count}" = "0" || test "${oldstat}" != "${stat}" 2>/dev/null ;
then
eval ${COMMAND1}
eval ${COMMAND2}
fi
done
trap '' 2
echo "Stopped because of stop.txt"
clean_s2s_inotify
|