LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-26-2002, 11:41 PM   #1
jayakrishnan
Member
 
Registered: Feb 2002
Location: India
Distribution: Slacky 12.1, XP
Posts: 992

Rep: Reputation: 30
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
 
Old 04-27-2002, 08:22 AM   #2
hanzerik
Member
 
Registered: Jan 2002
Location: Cheyenne Wyoming
Distribution: Debian/Raspbian/Mint
Posts: 717

Rep: Reputation: 32
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.
 
Old 04-27-2002, 08:40 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
adduser / useradd is a binary executable, not a script.
 
Old 04-27-2002, 05:39 PM   #4
hanzerik
Member
 
Registered: Jan 2002
Location: Cheyenne Wyoming
Distribution: Debian/Raspbian/Mint
Posts: 717

Rep: Reputation: 32
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.

Last edited by hanzerik; 04-27-2002 at 05:40 PM.
 
Old 04-29-2002, 12:35 AM   #5
jayakrishnan
Member
 
Registered: Feb 2002
Location: India
Distribution: Slacky 12.1, XP
Posts: 992

Original Poster
Rep: Reputation: 30
adduser is a binary file in RH.

Can anyone help?
 
Old 04-29-2002, 02:55 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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/)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell script within a C or C++ program Quantum0726 Programming 2 06-15-2005 09:14 PM
running SHell script from java anirudh Programming 2 01-07-2005 07:37 AM
Running shell script install, how? henrikanttonen Linux - Newbie 9 08-06-2004 08:46 PM
Running script as user that does not have shell sschueller Linux - General 1 04-24-2004 03:06 PM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration