Skip to content

Instantly share code, notes, and snippets.

@tonejito
Last active January 9, 2020 16:46
Show Gist options
  • Select an option

  • Save tonejito/09759d05b779281cc36d9bdccfe0d031 to your computer and use it in GitHub Desktop.

Select an option

Save tonejito/09759d05b779281cc36d9bdccfe0d031 to your computer and use it in GitHub Desktop.
Disk usage report with ncdu
#!/bin/bash
# /etc/cron.daily/ncdu
# Update disk usage report
# Andres Hernandez (tonejito)
# This script is released under the BSD license
# https://dev.yorhel.nl/ncdu
# git://g.blicky.net/ncdu.git/
# autoreconf -i && ./configure --prefix=/usr && make && make install
set -e
LOGGER=/usr/bin/logger
IONICE=/usr/bin/ionice
NICE=/usr/bin/nice
FLOCK=/usr/bin/flock
NCDU=/usr/bin/ncdu
WORK_DIR=/root
RUN_DIR=/run
test -x $NCDU || exit -1
# See ionice(1)
if [ -x $IONICE ] && $IONICE -c3 true 2>/dev/null
then
IONICE="$IONICE -c3"
else
IONICE=""
fi
$LOGGER '<ncdu>'
$FLOCK --nonblock $RUN_DIR/ncdu.daily.lock $IONICE $NICE -n 19 $NCDU -x0o $WORK_DIR/.ncdu /
$LOGGER '</ncdu>'

ncdu on older systems

On legacy servers you have to add the following line to configure.ac

AM_PROG_CC_C_O

And remove the following two if you are on a 32-bit system

AC_TYPE_INT64_T
AC_TYPE_UINT64_T

Then proceed to build as usual

autoreconf -i && ./configure --prefix=/usr && make && make install

Debian dependencies

aptitude --assume-yes install build-essential libtool pkg-config automake autoconf+M autotools-dev+M ncurses-dev libncurses-dev

= ^ . ^ =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment