next up previous contents index
suivant: Traduction de fichiers d'informations monter: Recherche des UID et précédent: Développement   Table des matières   Index

Programme obtenu

#!/bin/sh
#
#
#   SERVICE DES ADMINISTRATEURS:
#       Administration des utilisateurs
#       Recherche pour l'affectation d'un UID ou d'un GID
#
#   Programme: $DIR_USERS_BIN/searchid
#
#   Codes de retour:
#       OK          0
#       ERREUR      1
#       Autre       2,...
#
#   Exemples: searchid -u     Retourne le prochaine uid libre
#             searchid -g     Retourne le prochaine gid libre
#
#   Creation: S. Baudry
#
#   Modifications:
#

#-----------------------------------------------------------
# Initialisation
#
TMP_DIR=${TMP_DIR:=/home/adm/tmp}
START_UID=${START_UID:=1000}
START_GID=${START_GID:=1000}
PASSWD=${PASSWD:=/etc/passwd}
GROUP=${GROUP:=/etc/group}
AWK=${AWK:=/usr/ucb/gawk}

export TMP_DIR START_UID START_GID PASSWD GROUP AWK

#-----------------------------------------------------------
# Fonctions locales
#
_usage()
{
    echo "Usage: `basename $0` -u|-g" >&2
    exit 1
}

#-----------------------------------------------------------
# Analyse de la ligne de commande
#
#
# Teste le passage de parametre
#
if [ $# -lt 1 ]; then
    _usage
    exit 1
fi

case $1 in
    -u)
        map=$PASSWD
        start_id=$START_STUDENT_UID
        ;;

    -g)
        map=$GROUP
        start_id=$START_PROJECT_GID
        ;;
    *)
        _usage
        exit 1
        ;;
esac

#-----------------------------------------------------------
# Corps du programme
#

if [ ! -f $map ]; then
	echo $start_id
    exit 0
fi

#
# Calcul du numero a creer
#

no_id=` cut -f3 -d: $map                    |\
    sort -n -u                              |\
    $AWK -v min_id=$start_id '$1 >= min_id { print $0}' |\
    $AWK -v min_id=$start_id '
        BEGIN {
            affected_id=min_id
        }
        {
            if ( $1 == affected_id )
                affected_id ++
        }
        END {
            print affected_id
        }'`

#-----------------------------------------------------------
# Fin du programme
#

echo $no_id
exit 0



baudry@esme.fr