tests: update expect file for u_direct_io
[e2fsprogs.git] / scrub / e2scrub_all_cron.in
blobfcfe415fe09457b8dccfa14247c54d752bebc299
1 #!/bin/bash
3 # Copyright (C) 2018 Oracle. All Rights Reserved.
5 # Author: Darrick J. Wong <darrick.wong@oracle.com>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 # Run e2scrub_all from a cronjob if we don't have systemd and we're not
22 # running on AC power.
24 on_ac_power() {
25 local any_known=no
27 # try sysfs power class first
28 if [ -d /sys/class/power_supply ]; then
29 for psu in /sys/class/power_supply/*; do
30 if [ -r "$psu/type" ]; then
31 type=$(cat "$psu/type")
33 # ignore batteries
34 [ "$type" = "Battery" ] && continue
36 online=$(cat "$psu/online")
38 [ "$online" = 1 ] && return 0
39 [ "$online" = 0 ] && any_known=yes
41 done
43 [ "$any_known" = "yes" ] && return 1
46 # else fall back to AC adapters in /proc
47 if [ -d /proc/acpi/ac_adapter ]; then
48 for ac in /proc/acpi/ac_adapter/*; do
49 if [ -r "$ac/state" ]; then
50 grep -q on-line "$ac/state" && return 0
51 grep -q off-line "$ac/state" && any_known=yes
52 elif [ -r "$ac/status" ]; then
53 grep -q on-line "$ac/status" && return 0
54 grep -q off-line "$ac/status" && any_known=yes
56 done
58 [ "$any_known" = "yes" ] && return 1
61 # Can't tell, just assume we're on AC.
62 return 0
65 test -e @root_sbindir@/e2scrub_all || exit 0
66 test -e /run/systemd/system && exit 0
67 on_ac_power || exit 0
69 exec @root_sbindir@/e2scrub_all