xorl %eax, %eax

Linux user’s data script

leave a comment »

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$ 

Written by xorl

January 22, 2009 at 23:27

Posted in administration, linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s