BASE_DIR=$( dirname "${BIN_DIR}" )
LIB_DIR="${BASE_DIR}/lib"
CONF_DIR="${BASE_DIR}/etc"
+OLD_HOMES_DIR="_old_homes"
+
+EXCLUDE_DIRS="regina
+noemi
+elmar
+miriam
+nick
+stefanie
+esther
+juliane
+claudia
+anja
+ellen
+justus
+kira
+oliva
+anja.o
+erika
+mailbox
+barbara
+nicole
+alexandra
+lost+found
+patches
+TT_DB
+stuttgart
+momamemberships
+faxserver
+amdraht
+MM
+creative_vp1
+creative_vp2
+creative_vp3
+issybase
+hohes-c
+eventure
+surfpool
+db1n
+qbic
+test-ftd-de
+s+s
+conradmail
+CPAN
+newspool
+bms
+netuser
+ipunkt
+hamburg
+superagent
+cyberline
+slowtiger
+rsync
+db1n1
+db1n2
+unit2
+conrad
+sekt
+db2n2
+concheck
+oestereich
+teamkonzept
+work
+sachsenhausen
+scimone
+con_rep_2
+goodbye
+usenet
+cegame
+info
+newshabitat
+wodef
+barmermesse
+services
+Christina.Hoschka
+ahrens
+bachem
+bartels
+baumgarten
+brandis
+dietsch
+diezmann
+fisahn
+gamer
+hanusch
+head
+johnson
+keating
+kleffmann
+kotra
+kueppers
+kuppi
+luciana
+schade
+stehle
+steinbach
+tautenhahn
+thuerwaechter
+vorst
+CFO
+CEO
+_old_homes
+alf
+ceo
+idm
+info_visioplant
+pp.user
+pts.user
+COO
+Investorrelations"
if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
. "${LIB_DIR}/functions.rc"
DESCRIPTION=$( cat <<-EOF
Removes orphaned NFS home directories under ${CYAN}${NFS_HOMEDIR_PARENT}${NORMAL}
- and archives them under ${CYAN}${NFS_HOMEDIR_PARENT}/_old_homes${NORMAL}.
+ and archives them under ${CYAN}${NFS_HOMEDIR_PARENT}/${OLD_HOMES_DIR}${NORMAL}.
EOF
)
}
+#------------------------------------------------------------------------------
+check_dir() {
+
+ local hdir="${1}"
+ local bname=$( basename "${hdir}" )
+ local ex=
+ local skip="n"
+
+ debug "Checking directory '${CYAN}${NFS_HOMEDIRS}/${hdir}${NORMAL}' ..."
+
+ local owner=$( stat --format="%U" "${hdir}" )
+ if [[ "${owner}" != 'UNKNOWN' ]] ; then
+ debug "Owner: '${owner}'"
+ return
+ fi
+
+ for ex in $( echo "${EXCLUDE_DIRS}" | egrep -v "^[ ]*(#|$)" | sed -e 's/^[ ]*//' -e 's/[ ]*$//' ) ; do
+ if [[ "${bname}" == "${ex}" ]] ; then
+ skip="y"
+ break
+ fi
+ done
+ if [[ "${skip}" == "y" ]] ; then
+ info "Skipping '${CYAN}${NFS_HOMEDIRS}/${hdir}${NORMAL}'."
+ return
+ fi
+
+ info "Directory '${CYAN}${NFS_HOMEDIRS}/${hdir}${NORMAL}' is orphaned, cleaning it up"
+ ls -ld "${hdir}"
+ du -sm "${hdir}"
+
+ local j=0
+ local tarfile="${NFS_HOMEDIRS}/${OLD_HOMES_DIR}/$bname.$j.tar.gz"
+ while [[ -e "${tarfile}" ]] ; do
+ j=$(( $j + 1 ))
+ tarfile="${NFS_HOMEDIRS}/${OLD_HOMES_DIR}/$bname.$j.tar.gz"
+ done
+ debug "Creating tarfile: '${CYAN}${tarfile}${NORMAL}'"
+ local cmd="tar cfz \"${tarfile}\" \"${hdir}\""
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd="tar cfzv \"${tarfile}\" \"${hdir}\""
+ fi
+ debug "Executing: ${cmd}"
+ if [[ "${SIMULATE}" != "y" ]] ; then
+ eval ${cmd}
+ ls -l "${tarfile}"
+ else
+ debug "Tarfile '${tarfile}' not created."
+ fi
+
+ info "Removing directory '${CYAN}${NFS_HOMEDIRS}/${hdir}${NORMAL}' ..."
+ RM --recursive "${hdir}"
+
+}
+
+#------------------------------------------------------------------------------
+do_cleanup() {
+
+ cd "${NFS_HOMEDIRS}"
+
+ local dir=
+ local oifs="${IFS}"
+ IFS="
+"
+
+ for dir in $( ls -1 -U ) ; do
+ if [[ ! -d "${dir}" ]] ; then
+ continue
+ fi
+ if [[ "${dir}" == "${OLD_HOMES_DIR}" ]] ; then
+ continue
+ fi
+ check_dir "${dir}"
+ done
+ IFS="${oifs}"
+
+}
+
#------------------------------------------------------------------------------
main() {
get_options "$@"
+ set_locale "en_US.utf8"
+ info "Starting cleanup homedirs ..."
+ do_cleanup
+ info "Finished cleanup homedirs."
}
CYAN=""
NORMAL=""
-VERSION="0.1.0"
+VERSION="0.2.0"
-STD_SHORT_OPTIONS="dvhV"
-STD_LONG_OPTIONS="debug,verbose,nocolor,help,version"
+STD_SHORT_OPTIONS="sdvhV"
+STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
STD_USAGE_MSG=$( cat <<-EOF
+ -s|--simulate Simulation mode - dont apply any changes.
-d|--debug Debug output (bash -x).
-v|--verbose Set verbosity on.
--nocolor Dont use colors on display.
while true ; do
case "$1" in
+ -s|--simulate)
+ SIMULATE="y"
+ shift
+ ;;
-d|--debug)
DEBUG="y"
shift
shift
done
fi
-
+
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ echo
+ echo -e "${CYAN}Simulation mode!${NORMAL}"
+ echo "Nothing is really done."
+ echo
+ fi
}
echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >&2
}
+#------------------------------------------------------------------------------
+RM() {
+
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ debug "Simulated removing of: $*"
+ return
+ fi
+ if [[ "${VERBOSE}" != "y" ]] ; then
+ rm "$@"
+ else
+ rm --verbose "$@"
+ fi
+
+}
+
+#------------------------------------------------------------------------------
+set_locale() {
+
+ local new_locale="$1"
+ local loc=
+ local found="n"
+
+ local oifs="${IFS}"
+ IFS="
+"
+ for loc in $( locale -a ); do
+ if [[ "${loc}" == "${new_locale}" ]] ; then
+ found="y"
+ break
+ fi
+ done
+ IFS="${oifs}"
+
+ if [[ "${found}" != "y" ]] ; then
+ error "Locale '${RED}${new_locale}${NORMAL}' not found."
+ else
+ LANG="${new_locale}"
+ LC_ALL=
+ LC_CTYPE="${new_locale}"
+ LC_NUMERIC="${new_locale}"
+ LC_TIME="${new_locale}"
+ LC_COLLATE="${new_locale}"
+ LC_MONETARY="${new_locale}"
+ LC_MESSAGES="${new_locale}"
+ LC_PAPER="${new_locale}"
+ LC_NAME="${new_locale}"
+ LC_ADDRESS="${new_locale}"
+ LC_TELEPHONE="${new_locale}"
+ LC_MEASUREMENT="${new_locale}"
+ LC_IDENTIFICATION="${new_locale}"
+ fi
+
+}
+
# vim: filetype=sh ts=4 et