-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsync-loop.sh
executable file
·81 lines (77 loc) · 1.91 KB
/
sync-loop.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/env bash
#
# sync-sync-loop.sh: repeatedly invoke 'sync' in background loop in order
# to work around problem with battery-based power glitches (i.e., abrupt
# shutdowns).
#
# TODO:
# - Run this as a cron job.
#
# Uncomment following line(s) for tracing:
# - xtrace shows arg expansion (and often is sufficient)
# - verbose shows source commands as is (but usually is superfluous w/ xtrace)
#
## echo "$@"
## set -o xtrace
## set -o verbose
function usage() {
base=$(basename "$0");
echo "";
echo "usage: $0 [options]";
echo "options: [--delay n] [--help] [--trace] [--verbose] [--]";
echo "";
# TODO: two examples; also add alias to tomohara.bash
echo "examples:"
echo ""
echo "$0 --"
echo ""
echo "$base --delay 15 >| /tmp/$base.$$.log &"
echo ""
return
}
# Parse command-line options
#
delay=60
verbose="false"
# TODO: show_usage=(( "$1" != "" ))
show_usage=0; if [ "$1" = "" ]; then show_usage=1; fi
more_options=0; case "$1" in -*) more_options=1 ;; esac
# TODO: add option for maximum number of iterations
while [ "$more_options" = "1" ]; do
if [ "$1" = "--trace" ]; then
set -o xtrace
elif [ "$1" = "--help" ]; then
show_usage=1
break
elif [ "$1" = "--delay" ]; then
delay="$2"
shift
elif [ "$1" = "--verbose" ]; then
verbose="true"
elif [ "$1" = "--" ]; then
break
elif [ "$1" = "" ]; then
echo "Warning: internal error in $0"
break
else
echo "ERROR: Unknown option: $1"
show_usage=1
fi
shift
more_options=0; case "$1" in -*) more_options=1 ;; esac
done
if [ "$show_usage" = "1" ]; then
usage
exit
fi
# Issue disk cache synchronization and then sleep for a minute
## TODO: add other commands (e.g., sensors)
synch_count=0
echo "Running file system sync every $delay seconds"
while true; do
let synch_count++
$verbose && echo "synching (iteration $synch_count)"
sync
sync
sleep "$delay"
done