security.d/chk_homespace

Sat, 18 Jul 2020 15:55:11 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 18 Jul 2020 15:55:11 +0200
changeset 23
b66522a5726e
parent 20
1d18ebb9e279
permissions
-rw-r--r--

Version 0.23 some fixes for newer awk versions.

#!/bin/bash
#
#############################################################################
# Copyright (C) 2005-2014
#   
# Michiel Broek               <mbse at mbse.eu>
#
# This file is part of SlackSecCheckScripts.
#
# This package is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# SlackSecCheckScripts is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with MBSE BBS; see the file COPYING.  If not, write to the Free
# Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
#############################################################################


PATH=/sbin:/usr/sbin:/bin:/usr/bin

umask 077
TZ=UTC; export TZ
MP=/etc/passwd
LANG=C; export LANG

SECUREDIR=$(mktemp -d /tmp/_securedir.XXXXXX) || exit 1

trap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE

if ! cd "$SECUREDIR"; then
        echo "Can not cd to $SECUREDIR".
        exit 1
fi

MPBYPATH=secure1.$$
OUTPUT=secure2.$$


# These are used several times.
#
awk -F: '{ print $1 " " $3 " " $6 }' $MP > $MPBYPATH


while read name uid  homedir; do
    if [ -d ${homedir}/ ] && [ "`expr $uid \>= 1000`" == "1" ]; then
	USAGE=$(du -s --block-size=1048576 -h $homedir 2>/dev/null | cut -f 1)
	SPACE=$(df -khTP $homedir | tail -n 1 | awk '{ print $3 }')
	printf -- "%-16s  %6s  %6s  $homedir\n" $name $USAGE $SPACE
    fi
done < $MPBYPATH > $OUTPUT
if [ -s $OUTPUT ] ; then
    printf -- "\n        Diskspace used by users.\n\n"
    printf -- "Username            used    size  homedirectory\n"
    printf -- "----------------  ------  ------  -------------\n"
    cat $OUTPUT
fi

mercurial