shell-scripts/solus_utility/safe_remuser.sh

18 lines
515 B
Bash
Raw Normal View History

#!/usr/bin/env bash
# Create a backup of a user and remove them
# Must be run with sudo or as root
##Check if the user exists using getent command
user_exists=$(getent passwd $1)
#If the user doesn't exist, we need not perform the backup, just exit.
if [ -z "$user_exists" ]
then
echo "User '$1' does not exist"
else
echo "Creating backup of home dir for '$1'"
mkdir -p "/root/deleted_users"
tar czvf /root/deleted_users/"$1".tar.gz /home/"$1"
userdel -rf "$1"
echo "Removed user '$1'"
fi