Linux user’s data script
I was looking at some old stuff and I found a really old shell script that I used for cleaning up users’ accounts. I was about to delete it but the I thought that some people may find it useful so here it is. Probably it is not sufficient for todays standards but it was a nice solution to a quick clean-up.
sh-3.2$ cat clean_user.sh #!/bin/sh if [ $# -ne 1 ]; then echo "Usage: $0 <username>" exit 0 fi USRNAME=$1 ID=$(id -u) if [ $ID -ne 0 ]; then echo "You have to run this script as root!" exit 1 fi # Lock user account passwd -l $USRNAME # Remove user's files from /home rm -fr /home/$USRNAME/* # Kill user's processes skill -KILL $USRNAME # Remove user's cronjobs crontab -d $USRNAME # Remove user's files from /tmp and /opt rm -fr `find /tmp /opt -user $USRNAME` # Re-enable user's account passwd -u $USRNAME sh-3.2$