-
Notifications
You must be signed in to change notification settings - Fork 1
/
saveItAllD
executable file
·28 lines (23 loc) · 1.13 KB
/
saveItAllD
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
#!/bin/bash
INTERVAL="30m"
mutex() {
local file=$1 pid pids
exec 9>>"$file"
{ pids=$(fuser -f "$file"); } 2>&- 9>&-
for pid in $pids; do
[[ $pid = $$ ]] && continue
exec 9>&-
return 1 # Locked by a pid.
done
}
mutex /tmp/saveItAllD.lock || { echo "saveItAllD is already running." >&2; exit 1; }
while :
do
echo "Waiting $INTERVAL..."
sleep $INTERVAL
(x=0;while :; do x=`expr $x + 1`; echo $x; sleep 0.1s; done) | zenity --progress --auto-close --text="It has been $INTERVAL since you last saved your data.\nWe recommend that you save data now to prevent any possible data loss.\nData will automatically be saved in a few seconds.\n\nClick Cancel now if you do not wish to save data." --title="Save Data"
if [ "$?" = "0" ]; then
(sync; echo 100) | zenity --progress --no-cancel --auto-close --pulsate --text='Please wait...\n(Do NOT power down your computer!)' --title="Saving data..."
(p=0; while :; do echo $p; p=`expr $p + 20`; sleep 1s; done) | zenity --progress --auto-close --no-cancel --text='Data has been successfully saved!\n\nThis will close in 5 seconds.' --title='Data saved!'
fi
done