Copyright© 1997 Hugo Cisneiros, hugo@netdados.com.br
Versão 3.3







Aqui vai um exemplo de script para criar contas automaticamente, tipo usadas
para novos usuários de BBS, no caso desse exemplo, uma BBS Linux:

1. Crie um arquivo e dê a ele atributos:

touch /etc/visitor
chmod 755 /etc/visitor

2. Edite esse arquivo e coloque essa shell script (se quiser, pode modificar, use
   por seu próprio risco, não me responsabilizo por nada):

# ------ Inicio do Shell Script ------
#!/bin/bash
defgroup=100
defcountry=Finland
usernro=$[1+`cat /etc/default/lastuser`]

setterm -clear
setterm -ulcolor bright yellow
setterm -reverse on
echo " Welcome to Dream World BBS                                                  "
setterm -reverse off
echo
echo "Welcome to Dream World BBS (Linux)"
echo
echo This system has Linux operating system and it is UNIX system.
echo If you are not sure that you like to use UNIX, or don\'t know
echo how to use it. Please, log in system as \"help\" first and read
echo more information BEFORE you log in. I must tell you that UNIX
echo is not user friendly, but many people like it anyway.
echo
echo If you like to go on, please give me ALL information correcly.
echo You can abort this \"questonaire\" with \< CTRL-C\ > anytime you like.
echo
echo -n "Your FIRST- and LASTNAME: "
read name
echo
echo -n "Street Address    : "
read street
echo -n "ZipCode and City  : "
read city
echo -n "Country           : "
read country
if test $country. = .; then country=$defcountry;fi
echo
echo "Please, remember also areacode (like: 921-4389843)"
echo
echo -n "Voice phone: "
read voice
echo -n "Data phone : "
read data
echo
echo "   1 - /bin/sh                  6 - /bin/ksh "
echo "   2 - /bin/bash                7 - /bin/sash"
echo "   3 - /bin/bwbasic             8 - /bin/tcsh"
echo "   4 - /bin/chsh                9 - /bin/zsh "
echo "   5 - /bin/csh                              "
echo
echo -n "\"default\" shell to use (or press enter): "
read shell
vara=0
if test $shell. = "9".; then shell="/bin/sh"     ; vara=1; fi
if test $shell. = "8".; then shell="/bin/tcsh"   ; vara=1; fi
if test $shell. = "7".; then shell="/bin/sash"   ; vara=1; fi
if test $shell. = "6".; then shell="/bin/ksh"    ; vara=1; fi
if test $shell. = "5".; then shell="/bin/csh"    ; vara=1; fi
if test $shell. = "4".; then shell="/bin/chsh"   ; vara=1; fi
if test $shell. = "3".; then shell="/bin/bwbasic"; vara=1; fi
if test $shell. = "2".; then shell="/bin/bash"   ; vara=1; fi
if test $shell. = "1".; then shell="/bin/sh"     ; vara=1; fi
if test $vara   =  0  ; then shell="/bin/bash"   ; vara=1; fi
setterm -clear
setterm -reverse on
echo " Welcome to Dream World BBS                                                  "
setterm -reverse off
echo
echo Now you must choose your \"login name\" it is 8 characters long
echo and contains a-z A-Z 0-9 chars.
setterm -reverse on
echo login can be 8 chars and ONE WORD !!!!!!!
setterm -reverse off
echo
setterm -underline on
echo REMEMBER. In unix upper- and lowercase letters ARE NOT SAME!
echo And use ONLY LOWERCASE letters in your login name... PLEASE!
setterm -underline off
echo
echo
vara=1
while test $vara = 1
do
	echo -n "Login: ";read login
	if test . = `grep $login":" /etc/passwd|cut -d: -f1`.
		then
			vara=0
			break
		else
			echo Login is allready in use\!
	fi
done
echo
echo "Please, wait few seconds... (Don't interrupt)"
echo $login:x:$usernro:$defgroup:$name:/home/$login:$shell >> /etc/passwd
echo $usernro > /etc/default/lastuser
echo $usernro $login:"Name   : "$name    >> /usr/adm/newuser.q-a
echo $usernro $login:"Address: "$street  >> /usr/adm/newuser.q-a
echo $usernro $login:"       : "$city    >> /usr/adm/newuser.q-a
echo $usernro $login:"Country: "$country >> /usr/adm/newuser.q-a
echo $usernro $login:"Voice  : "$voice   >> /usr/adm/newuser.q-a
echo $usernro $login:"Data   : "$data    >> /usr/adm/newuser.q-a
mkdir /home/$login
cp -r /etc/skel/. /home/$login
echo -n > /usr/spool/mail/$login
chown -R $login.$defgroup /home/$login/.
chmod 660 /usr/spool/mail/$login
chown $login.mail /usr/spool/mail/$login
echo -n > /logins/$login
chmod 600 /logins/$login
chmod 700 /home/$login
chown $login.$defgroup /logins/$login
grep -v "users:" /usr/lib/aliases > /usr/lib/aliases.new
echo `grep "users:" /usr/lib/aliases`,$login >> /usr/lib/aliases.new
mv -f /usr/lib/aliases.new /usr/lib/aliases
/usr/lib/smail/mkaliases > /dev/null 2> /dev/null
passwd $login

setterm -clear
echo
echo Now try login again with you new "login"...
echo
# ------ Fim do Shell Script ------

3. Adicione o login visitor, ou outro que você quiser:

/etc/passwd:
visitor:0:0:Visitor - Script novo usuario:/:/etc/visitor

Pronto, está feito. Quando o usuário visitor se logar, o shell script
será rodado e ele poderá criar sua nova conta e ter uma shell





Voltar ao Índice principal