A sample script to add a new user


[Home]  [Site Map]  [Docs]  [Links]  [Help]  [About]  [Contact]  [Warning]


#!/bin/bash
#

# create a new user account
if [ $# -lt 1 ]; then
echo "Usage: newuser user [comment]"
exit 1
fi

# add user $1 to the group "xyz"
echo Adding user $1 ...
if [ $# -eq 1 ]; then
useradd -d /home/$1 -m -g xyz -s /bin/bash $1
else
useradd -d /home/$1 -m -c $2 -g xyz -s /bin/bash $1
fi
if [ $? -ne 0 ]; then
exit 1
fi

# change password interactively
passwd $1
if [ $? -ne 0 ]; then
echo "passwd failed! Deleting user ..."
userdel $1
exit 1
fi

# links for user and others
ln -s /home/$1 /home/data/user/$1

chmod g+rx /home/$1

# mailbox-configuration
ln -s /home/mail/xyz /home/$1/.xyz@foo.net
ln -s /home/xyz/Archive /home/$1/.Archive

cp /home/fabian/.mailboxlist /home/$1/
chown $1 /home/$1/.mailboxlist

rm -Rf /home/$1/.xauth

# start office setup if within X
if [ "$DISPLAY" = "" ]; then
echo "Not in X! Cannot setup office ..."
exit 2
fi

xhost +
su $1 -l -c "/bin/bash /opt/office52/program/setup"
xhost -



[Home]  [Site Map]  [Docs]  [Links]  [Help]  [About]  [Contact]  [Warning]



Copyright © 2002 by Pablo Hoertner. All rights reserved.
Last changes: Thursday, December 4