minor bug fix
[distro-setup] / btrfsmaint
index 4bb22464086f2c7894f42dcbab0050eb1c184475..c410b7b3503359309ab6938f5c233f7193cd6a3e 100755 (executable)
@@ -16,9 +16,17 @@ e() { echo "cron: $*"; "$@"; }
 
 check-idle() {
     export DISPLAY=:0
-    idle_time=$(xprintidle 2>/dev/null) ||:
     # 3 hours, assume a movie might run that long.
-    if [[ $idle_time ]] && (( idle_time < 1000 * 60 * 60 * 3 )); then
+    idle_limit=$((1000 * 60 * 60 * 3))
+    idle_time=$idle_limit
+    id=999
+    while id $((++id)) &>/dev/null; do
+        new_idle_time=$(sudo -u \#$id xprintidle 2>/dev/null) ||:
+        if [[ $new_idle_time && $new_idle_time -lt $idle_time ]]; then
+            idle_time=$new_idle_time
+        fi
+    done
+    if (( idle_time < idle_limit )); then
         idle=false
     else
         idle=true
@@ -76,7 +84,7 @@ for x in $($fnd --output "SOURCE" --nofsroot | sort -u); do
         # the wiki recommends 30 days or so, but
         # it makes the comp lag like shit for a day,
         # so I'm going with 90 days.
-        if (( $date > `date +%s` - 60*60*24*30 )); then
+        if (( date > $(date +%s) - 60*60*24*30 )); then
             echo "cron: skiping scrub of $mnt"
             continue
         fi