3 #=======================================================================
5 # File ID: 29dba898-4962-11df-adc3-d5e071bed206
7 # Shortcut to check various stuff.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
29 " -n "$progname" -- "$@
")"
30 test "$?" = "0" ||
exit 1
36 opt_maxtemp
=$std_maxtemp
43 -h|
--help) opt_help
=1; shift ;;
44 --maxtemp) opt_maxtemp
=$2; shift 2 ;;
45 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
46 --space) opt_space
=$2; shift 2 ;;
47 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
48 --version) echo $progname $VERSION; exit 0 ;;
49 -W|
--wait) opt_wait
=1; shift ;;
51 *) echo $progname: Internal error
>&2; exit 1 ;;
54 opt_verbose
=$
(($opt_verbose - $opt_quiet))
56 if test "$opt_help" = "1"; then
57 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
60 Usage: $progname [options] [command]
67 Define maximum acceptable temperature for "$progname temp-warn".
68 Default value: $std_maxtemp
70 Be more quiet. Can be repeated to increase silence.
72 When used with "dfull":
73 Estimate time until the free disk space reaches BYTES. This value
74 is parsed by numfmt(1) from GNU coreutils, check the man page for
75 allowed values. Examples: 10M = 10000000, 10Mi = 10485760.
77 Increase level of verbosity. Can be repeated.
79 Print version information.
81 When used with "dfull":
82 Wait until the amount of free space changes before starting the
86 Display free space of all local disks every 2nd second until
89 Run a query against pool.ntp.org to see how accurate the system
92 Display estimated time until the current disk is full based on the
93 disk usage since the script was started.
95 Display free space of all local disks, sorted by free space.
97 Follow the kernel log and display new entries immediately when they
100 Check that the network is up by issuing a ping command until
103 Display free space of the current disk every second until
106 Display current temperature.
108 Loop and check CPU temperature. If it gets too high, create an
109 xmessage(1) window and send a warning to stderr.
115 space_val
="$(numfmt --from=auto --round=nearest -- $opt_space)"
116 test -z "$space_val" && {
117 echo "$progname: Invalid value in --space argument" >&2
120 test $opt_verbose -ge 1 &&
121 echo "$progname: Using --space $space_val" >&2
124 df
-B1 "$1" -P |
tail -1 |
tr -s ' ' | cut
-f 4 -d ' ' \
125 | hum | rmspcall |
tr -d '\n'
129 df
-B 1 "$1" -P |
tail -1 |
tr -s ' ' | cut
-f 4 -d ' ' |
tr -d '\n'
133 mount |
grep ^
/dev
/ | cut
-f 3 -d ' ' |
sort |
while read f
; do
134 [ "$f" = "/boot" -o "$f" = "/boot/efi" ] && continue
136 if test "$f" = "/"; then
140 echo "$f " |
rev | cut
-f 1 -d / |
rev |
tr -d '\n'
147 [ -z "$1" ] && { echo $progname: No
command specified
>&2; exit 1; }
148 if test "$1" = "allspace"; then
151 curr
="$(all_free_space)"
152 if test "$curr" != "$prev"; then
154 echo -n "$(date +"%d
%H
:%M
:%S
")$curr$(tput el)"
159 elif test "$1" = "date"; then
160 ntpdate
-q pool.ntp.org
161 elif test "$1" = "df"; then
162 df
-h --si |
grep ^Filesystem
163 df
-h --si --total |
grep -e /dev
/ -e ^total |
sort -h -k4
164 elif test "$1" = "dfull"; then
165 if test "$opt_wait" = "1"; then
167 curr_df
="$(df -B1 .)"
168 echo -n $progname: Waiting
for change
in free space...
>&2
169 while test "$beg_df" = "$curr_df"; do
171 curr_df
="$(df -B1 .)"
176 origtime
="$(date -u +"%Y-
%m-
%d
%H
:%M
:%S.
%N
")"
177 origdf
=$
(( $
(free_space_bytes .
) - $space_val ))
183 currtime
="$(date -u +"%Y-
%m-
%d
%H
:%M
:%S.
%N
")"
185 currdf
=$
(( $
(free_space_bytes .
) - $space_val ))
187 goal "$origtime" "$origdf" 0 "$currdf" 2>/dev/null
189 dfdiff
="$(( $currdf-$origdf ))"
190 goalint
=$
(echo $goal_output |
awk '{print $1}' |
sed 's/\..*//')
191 goaldate
=$
(echo $goal_output |
awk '{print $2}')
192 goaltime
=$
(echo $goal_output |
awk '{print $3}' |
sed 's/\..*//')
193 cl_goalint
=$
(echo $goalint |
wc -L)
194 cl_goaltime
=$
(echo $goaltime |
wc -L)
195 cl_dfdiff
=$
(echo $dfdiff | hum |
wc -L)
196 seconds
=$
(echo $currsec-$origsec |
bc)
198 test $cl_goalint -gt $ml_goalint && ml_goalint
=$cl_goalint
199 test $cl_goaltime -gt $ml_goaltime && ml_goaltime
=$cl_goaltime
200 test $cl_dfdiff -gt $ml_dfdiff && ml_dfdiff
=$cl_dfdiff
202 if test "$(echo "$currdf < $prevdf" | bc)" = "1"; then
203 t_diskfree
="$(tput bold; tput setaf 1)"
204 t_diskfree_reset
="$(tput sgr0)"
205 elif test "$(echo "$currdf > $prevdf" | bc)" = "1"; then
206 t_diskfree
="$(tput bold; tput setaf 2)"
207 t_diskfree_reset
="$(tput sgr0)"
213 if test -n "$goal_output"; then
218 "%-${ml_goaltime}s "\
219 "diff: %s%-${ml_dfdiff}s%s "\
227 "$(echo $dfdiff | hum)" \
228 "$t_diskfree_reset" \
230 "$(echo $currdf | hum)" \
231 "$t_diskfree_reset" \
234 if test $seconds -gt 0; then
236 printf 'scale=0; %d/%u\n' $dfdiff $seconds |
242 printf "\\n$progname dfull: No changes yet, %s%s%s bytes free%s" \
244 "$(echo $currdf | hum)" \
245 "$t_diskfree_reset" \
251 elif test "$1" = "kern"; then
252 tail -Fq /var
/log
/kern.log
/var
/log
/syslog
/var
/log
/auth.log \
253 |
grep -v " $(hostname) CRON"
254 elif test "$1" = "space"; then
257 lastspace
=$
(free_space .
)
258 if test "$lastspace" != "$prevlast"; then
259 echo -n " $lastspace $(tput el)"
264 elif test "$1" = "temp"; then
265 temperature_file
=/sys
/devices
/virtual
/thermal
/thermal_zone
0/temp
266 if test ! -e "$temperature_file"; then
267 echo $progname: $temperature_file: File not found
>&2
268 echo $progname: Cannot
read temperature
>&2
273 echo -n $
(cat "$temperature_file")
276 elif test "$1" = "temp-warn" -o "$1" = "tw"; then
278 dispfile
="/tmp/sj_tw.$(date +%s).$$.tmp"
279 if test -e "$dispfile"; then
280 echo $progname: $dispfile: Tempfile already exists
, that
\'s spooky
>&2
284 currtemp
="$($progname temp)"
285 if test -z "$currtemp"; then
286 echo -n "$progname: Unable to read temperature, " >&2
287 echo \"$progname temp
\" returned nothing
>&2
290 if test "$currtemp" != "$prevtemp"; then
291 echo $
(date -u +"%Y-%m-%dT%H:%M:%SZ") $currtemp >>~
/log
/temp.log
292 echo -n " $currtemp $(tput el)"
295 if test $
(echo "$currtemp > $opt_maxtemp" |
bc) = "1"; then
296 grep Blimey
"$dispfile" 2>/dev
/null |
grep -q .
&& rm "$dispfile"
297 if test ! -e $dispfile; then
298 warning
="Oi! The temperature is $currtemp!"
299 xmessage
-button Blimey
-print "$warning" >"$dispfile" &
305 echo -n "$progname: $warning"
314 elif test "$1" = "ping"; then
315 test -d /n900
/.
&& sudo
=sudo ||
unset sudo
317 $sudo ping 178.79.142.16
319 echo ============================================
322 echo $progname: $1: Unknown
command >&2