Re: User creation script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ashley M. Kirchner a écrit :
> 
>    Anyone have pointers (or examples) of a script that can be used to
> create new users and set their password at the same time?  I need
> something I can call like so:
> 
>    script USERNAME PASSWORD

not exactly, here a script I have done to had user from a list, you can
adapt it to fit your needs. This script create users with temporary
crypted password, add them to the mail server and crate an elementary
web page... Choose what you want (sorry for comments in French!):

#!/bin/bash

cat < list-of-users | while true
do
   read ligne
   if [ "$ligne" = "" ]; then break; fi
   echo "lecture de la ligne --->" $ligne
   set -- $ligne
   PRENOM=$1
   PRENOM2=$2
   NOM=$3
   LOGIN=$4
   COURRIER=$5
   LIEU=$6
   GROUP=$7
   PASSWD=`echo $PRENOM | cut -c1``echo $NOM | cut -c1`2005
#
   echo prenom=$PRENOM, prenom2=$PRENOM2 nom=$NOM login=$LOGIN
passwd=$PASSWD courrier=$COURRIER lieu=$LIEU
#
#creation des utilisateurs
   CRYPTPASSWORD=`/usr/sbin/slappasswd  -h {MD5} -c '$1$%.8s' -s $PASSWD
| cut -d "}" -f2`
   /usr/sbin/adduser -s /usr/bin/rssh  -p $CRYPTPASSWORD -g $GROUP $LOGIN
   echo "$COURRIER, \\$LOGIN" > /home/$LOGIN/\.forward
#
#courrier
   mkdir /home/$LOGIN/mail/
   cp /root/.subscriptions /home/$LOGIN/mail/
   echo "$PRENOM2.$LOGIN:  $LOGIN" >> /etc/mail/aliases
   echo "$LOGIN: $PRENOM2.$LOGIN" >> /etc/mail/revaliases
#
#page web
   mkdir /home/$LOGIN/public_html
   cat << xxFINxx > /home/$LOGIN/public_html/index.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>$PRENOM $NOM</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="MSSmartTagsPreventParsing" content="TRUE">


<!-- <link rel="stylesheet" href="styles/style.css" type="text/css"> -->

<style type="text/css">
body {font-family: verdana, arial, sans-serif ;
     margin-left : 1em ;
     margin-right : 1em ;
     margin-top : 1em ;
     margin-bottom : 1em ;
     }
a:link, a:visited  {
        font: 12px verdana, arial, sans-serif;
        font-weight: bold;
        text-decoration: none;
        color:#555555;
        }
a:hover {
        font-weight: bold;
        text-decoration: none;
        color: #000;
        background: #6C0202;
       }

</style>

</head>

<body>
<table border="0" rules="none">
  <tr bgcolor="#6C0202" width="100%">
    <th>
      <img src="mylogo.png"  alt="logo mylogo">
    </th>
    <th width="100%">&nbsp;</th>
  </tr>
</table>

<h1>$PRENOM $NOM</h1>


<h4>$LIEU</h4>

<h4>Courriel&nbsp;: <a
href="mailto:$PRENOM2.$LOGIN@xxxxxxxxxxxxxxxxxx";>$PRENOM2.$LOGIN@xxxxxxxxxxxxxxxxxx</a></h4>

<hr>

<p></p>

</body> </html>
xxFINxx
#
   cp /root/mylogo.png /home/$LOGIN/public_html/
   chown -R $LOGIN.$GROUP /home/$LOGIN
   chmod 711 /home/$LOGIN
   chmod 600 /home/$LOGIN/.forward
   chmod 644 /home/$LOGIN/public_html/*
   chmod 711 /home/$LOGIN/public_html/
   chmod 700 /home/$LOGIN/mail/
   chmod 600 /home/$LOGIN/mail/.subscriptions
 done

cd /etc/mail/

/usr/bin/newaliases
/usr/sbin/sendmail -bi -oA/etc/mail/revaliases

echo $?

<-----------------end script

The list is a simple text file with one line per user like this:

John john Doe doe jd@xxxxxxxxxxx lieu name-of-group



- --
François Patte
UFR de mathématiques et informatique
Université René Descartes
http://www.math-info.univ-paris5.fr/~patte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFGMKBtdE6C2dhV2JURAvW0AJ4v+ouQ4exljjLKnWWvMyZ/yGOEiACgiogX
1C5l7UmgUX8iPabj5PUQumk=
=GPTX
-----END PGP SIGNATURE-----


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux