LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Running a shell script when a user is added. (https://www.linuxquestions.org/questions/linux-general-1/running-a-shell-script-when-a-user-is-added-19577/)

jayakrishnan 04-26-2002 11:41 PM

Running a shell script when a user is added.
 
Hi all

when ever a new user is added a shell script should be executed, which creates a directory in /var/www/html/<username>.

how do i do that?

thanks for any help.

regards
jayakrishnan

hanzerik 04-27-2002 08:22 AM

Take a look at the adduser script, you could change the script to make a users default home directory /var/www/html/<username> , if you edit adduser script i would suggest making a backup and nameing it a different name ie: adduser-html. And just use that for your www users.

acid_kewpie 04-27-2002 08:40 AM

adduser / useradd is a binary executable, not a script.

hanzerik 04-27-2002 05:39 PM

well, I did a more on adduser on my slackware box and it was a plain text script. It has references back to useradd and the passwd commands.

#!/bin/sh
# adduser script for use with shadow passwords and useradd command.
# by Hrvoje Dogan <hdogan@student.math.hr>, Dec 1995.
# Modified by Patrick Volkerding, Oct 1997, Mar 1999, May 2000.

echo
echo -n "Login name for new user []: "
read LOGIN
if [ -z "$LOGIN" ]; then
echo "Come on, man, you can't leave the login field empty..."
exit
fi
echo
echo -n "User id for $LOGIN [ defaults to next available]: "
read ID
GUID="-u $ID"
if [ -z "$ID" ]; then
GUID=""
fi

echo
echo -n "Initial group for $LOGIN [users]: "
read GID
if [ -z "$GID" ]; then
GID="users"
fi
GGID="-g $GID"

echo
echo "Additional groups for $LOGIN (seperated"
echo -n "with commas, no spaces) []: "
read AGID
GAGID="-G $AGID"
if [ -z "$AGID" ]; then
GAGID=""
fi

echo
echo -n "$LOGIN's home directory [/home/$LOGIN]: "
read HME
if [ -z "$HME" ]; then
HME="/home/$LOGIN"
fi
GHME="-d $HME"

echo
echo -n "$LOGIN's shell [/bin/bash]: "
read SHL
GSHL="-s $SHL"
if [ -z "$SHL" ]; then
GSHL="-s /bin/bash"
SHL="/bin/bash"
fi

echo
echo -n "$LOGIN's account expiry date (YYYY-MM-DD) []: "
read EXP
GEXP="-e $EXP"
if [ -z "$EXP" ]; then
GEXP=""
fi
echo
echo "OK, I'm about to make a new account. Here's what you entered so far:"
echo
echo New login name: $LOGIN
if [ -z "$GUID" ]; then
echo New UID: [Next available]
else
echo New UID: $UID
fi
if [ -z "$GGID" ]; then
echo Initial group: users
else
echo Initial group: $GID
fi
if [ -z "$GAGID" ]; then
echo Additional groups: [none]
else
echo Additional groups: $AGID
fi
if [ -z "$GHME" ]; then
echo Home directory: /home/$LOGIN
else
echo Home directory: $HME
fi
if [ -z "$GSHL" ]; then
echo Shell: /bin/bash
else
echo Shell: $SHL
fi
if [ -z "$GEXP" ]; then
echo Expiry date: [no expiration]
else
echo Expiry date: $EXP
fi
echo
echo "This is it... if you want to bail out, hit Control-C. Otherwise, press"
echo "ENTER to go ahead and make the account."
read FOO
echo
echo Making new account...
/usr/sbin/useradd $GHME -m $GEXP $GGID $GAGID $GSHL $GUID $LOGIN
if [ -d $HME ]; then
chmod 711 $HME
fi
echo
/usr/bin/chfn $LOGIN
echo
/usr/bin/passwd $LOGIN
echo "Done..."



Maybe its different in RH or Mandy, I dont have my RH box up right now.

jayakrishnan 04-29-2002 12:35 AM

adduser is a binary file in RH.

Can anyone help?

acid_kewpie 04-29-2002 02:55 AM

well why can't you just run both commands in a shell script? it's not exactly difficult...

#!/bin/sh
useradd $*
mkdir /var/www/html/$1

i'd recommend just setting up your webserver properly tho, so you give users PROPER web locations in their /home dir. (www.web.com/~jeff --> /home/jeff/public_html/)


All times are GMT -5. The time now is 04:32 AM.