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 #=======================================================================
27 " -n "$progname" -- "$@
")"
28 test "$?" = "0" ||
exit 1
34 opt_maxtemp
=$std_maxtemp
40 -h|
--help) opt_help
=1; shift ;;
41 --maxtemp) opt_maxtemp
=$2; shift 2 ;;
42 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
43 --space) opt_space
=$2; shift 2 ;;
44 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
45 --version) echo $progname $VERSION; exit 0 ;;
47 *) echo $progname: Internal error
>&2; exit 1 ;;
50 opt_verbose
=$
(($opt_verbose - $opt_quiet))
52 if test "$opt_help" = "1"; then
53 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
56 Usage: $progname [options] [command]
63 Define maximum acceptable temperature for "$progname temp-warn".
64 Default value: $std_maxtemp
66 Be more quiet. Can be repeated to increase silence.
68 When used with "dfull":
69 Estimate time until the free disk space reaches BYTES. This value
70 is parsed by numfmt(1) from GNU coreutils, check the man page for
71 allowed values. Examples: 10M = 10000000, 10Mi = 10485760.
73 Increase level of verbosity. Can be repeated.
75 Print version information.
78 Display free space of all local disks every 2nd second until
81 Run a query against pool.ntp.org to see how accurate the system
84 Display estimated time until the current disk is full based on the
85 disk usage since the script was started.
87 Display free space of all local disks, sorted by free space.
89 Follow the kernel log and display new entries immediately when they
92 Check that the network is up by issuing a ping command until
95 Display free space of the current disk every second until
98 Display current temperature.
100 Loop and check CPU temperature. If it gets too high, create an
101 xmessage(1) window and send a warning to stderr.
107 space_val
="$(numfmt --from=auto --round=nearest -- $opt_space)"
108 test -z "$space_val" && {
109 echo "$progname: Invalid value in --space argument" >&2
112 test $opt_verbose -ge 1 &&
113 echo "$progname: Using --space $space_val" >&2
116 df
-h --si "$1" -P |
tail -1 |
tr -s ' ' | cut
-f 4 -d ' ' |
tr -d '\n'
120 df
-B 1 "$1" -P |
tail -1 |
tr -s ' ' | cut
-f 4 -d ' ' |
tr -d '\n'
124 mount |
grep ^
/dev
/ | cut
-f 3 -d ' ' |
sort |
while read f
; do
125 if test "$f" = "/"; then
129 echo "$f " |
rev | cut
-f 1 -d / |
rev |
tr -d '\n'
137 [ -z "$1" ] && { echo $progname: No
command specified
>&2; exit 1; }
138 if test "$1" = "allspace"; then
141 curr
="$(all_free_space)"
142 if test "$curr" != "$prev"; then
144 echo -n "$(date +"%d
%H
:%M
:%S
") $curr$(tput el)"
149 elif test "$1" = "date"; then
150 ntpdate
-q pool.ntp.org
151 elif test "$1" = "df"; then
152 df
-h --si |
grep ^Filesystem
153 df
-h --si --total |
grep -e /dev
/ -e ^total |
sort -h -k4
154 elif test "$1" = "dfull"; then
156 origtime
="$(date -u +"%Y-
%m-
%d
%H
:%M
:%S.
%N
")"
157 origdf
=$
(( $
(free_space_bytes .
) - $space_val ))
163 currtime
="$(date -u +"%Y-
%m-
%d
%H
:%M
:%S.
%N
")"
165 currdf
=$
(( $
(free_space_bytes .
) - $space_val ))
167 goal "$origtime" "$origdf" 0 "$currdf" 2>/dev/null
169 dfdiff
="$(( $currdf-$origdf ))"
170 goalint
=$
(echo $goal_output |
awk '{print $1}' |
sed 's/\..*//')
171 goaldate
=$
(echo $goal_output |
awk '{print $2}')
172 goaltime
=$
(echo $goal_output |
awk '{print $3}' |
sed 's/\..*//')
173 cl_goalint
=$
(echo $goalint |
wc -L)
174 cl_goaltime
=$
(echo $goaltime |
wc -L)
175 cl_dfdiff
=$
(echo $dfdiff | hum |
wc -L)
176 seconds
=$
(echo $currsec-$origsec |
bc)
178 test $cl_goalint -gt $ml_goalint && ml_goalint
=$cl_goalint
179 test $cl_goaltime -gt $ml_goaltime && ml_goaltime
=$cl_goaltime
180 test $cl_dfdiff -gt $ml_dfdiff && ml_dfdiff
=$cl_dfdiff
182 if test "$(echo "$currdf < $prevdf" | bc)" = "1"; then
183 t_diskfree
="$(tput bold; tput setaf 1)"
184 t_diskfree_reset
="$(tput sgr0)"
185 elif test "$(echo "$currdf > $prevdf" | bc)" = "1"; then
186 t_diskfree
="$(tput bold; tput setaf 2)"
187 t_diskfree_reset
="$(tput sgr0)"
193 if test -n "$goal_output"; then
198 "%-${ml_goaltime}s "\
199 "diff: %s%-${ml_dfdiff}s%s "\
207 "$(echo $dfdiff | hum)" \
208 "$t_diskfree_reset" \
210 "$(echo $currdf | hum)" \
211 "$t_diskfree_reset" \
214 if test $seconds -gt 0; then
216 printf 'scale=0; %d/%u\n' $dfdiff $seconds |
222 printf "\\n$progname dfull: No changes yet, %s%s%s bytes free%s" \
224 "$(echo $currdf | hum)" \
225 "$t_diskfree_reset" \
231 elif test "$1" = "kern"; then
232 tail -Fq /var
/log
/kern.log
/var
/log
/syslog
/var
/log
/auth.log \
233 |
grep -v " $(hostname) CRON"
234 elif test "$1" = "space"; then
237 lastspace
=$
(free_space .
)
238 if test "$lastspace" != "$prevlast"; then
239 echo -n " $lastspace $(tput el)"
244 elif test "$1" = "temp"; then
245 temperature_file
=/sys
/devices
/virtual
/thermal
/thermal_zone
0/temp
246 if test ! -e "$temperature_file"; then
247 echo $progname: $temperature_file: File not found
>&2
248 echo $progname: Cannot
read temperature
>&2
253 echo -n $
(cat "$temperature_file")
256 elif test "$1" = "temp-warn" -o "$1" = "tw"; then
258 dispfile
="/tmp/sj_tw.$(date +%s).$$.tmp"
259 if test -e "$dispfile"; then
260 echo $progname: $dispfile: Tempfile already exists
, that
\'s spooky
>&2
264 currtemp
="$($progname temp)"
265 if test -z "$currtemp"; then
266 echo -n "$progname: Unable to read temperature, " >&2
267 echo \"$progname temp
\" returned nothing
>&2
270 if test "$currtemp" != "$prevtemp"; then
271 echo $
(date -u +"%Y-%m-%dT%H:%M:%SZ") $currtemp >>~
/log
/temp.log
272 echo -n " $currtemp $(tput el)"
275 if test $
(echo "$currtemp > $opt_maxtemp" |
bc) = "1"; then
276 grep Blimey
"$dispfile" 2>/dev
/null |
grep -q .
&& rm "$dispfile"
277 if test ! -e $dispfile; then
278 warning
="Oi! The temperature is $currtemp!"
279 xmessage
-button Blimey
-print "$warning" >"$dispfile" &
285 echo -n "$progname: $warning"
294 elif test "$1" = "ping"; then
295 test -d /n900
/.
&& sudo
=sudo ||
unset sudo
297 $sudo ping 178.79.142.16
299 echo ============================================
302 echo $progname: $1: Unknown
command >&2