<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: debian code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 17:52:57 GMT</pubDate>
    <description>DZone Snippets: debian code</description>
    <item>
      <title>Add many users in a Debian system v0.2</title>
      <link>http://snippets.dzone.com/posts/show/4980</link>
      <description>Create many users in a Debian system using a text file as argument&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;#******************************************************************************#&lt;br /&gt;# AddManyUsers-deb.sh - Create many users in a Debian system using a text file #&lt;br /&gt;# 			as argument					       #&lt;br /&gt;#   Copyright (C) 2008 - written by flynets - &lt;flynets&lt;at&gt;autistici&lt;dot&gt;org&gt;   # &lt;br /&gt;#   AddManyUsers-deb is free software: you can redistribute it and/or modify   #&lt;br /&gt;#   it under the terms of the GNU General Public License as published by       #&lt;br /&gt;#   the Free Software Foundation, either version 3 of the License, or          #&lt;br /&gt;#   any later version.							       #&lt;br /&gt;#									       #&lt;br /&gt;#   AddManyUsers-deb is distributed in the hope that it will be useful,	       #&lt;br /&gt;#   but WITHOUT ANY WARRANTY; without even the implied warranty of             #&lt;br /&gt;#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the	       #&lt;br /&gt;#   GNU General Public License for more details.			       #&lt;br /&gt;#									       #&lt;br /&gt;#   You should have received a copy of the GNU General Public License	       #&lt;br /&gt;#   along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.      #&lt;br /&gt;#******************************************************************************#&lt;br /&gt;&lt;br /&gt;# Checks if you have the right privileges&lt;br /&gt;if [ "$USER" = "root" ]&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;# CHANGE THIS PARAMETERS FOR A PARTICULAR USE&lt;br /&gt;PERS_HOME="/home/"&lt;br /&gt;PERS_SH="/bin/bash"&lt;br /&gt;&lt;br /&gt;   # Checks if there is an argument&lt;br /&gt;   [ $# -eq 0 ] &amp;&amp; { echo &gt;&amp;2 ERROR: You may enter as an argument a text file containing users, one per line. ; exit 1; }&lt;br /&gt;   # checks if there a regular file&lt;br /&gt;   [ -f "$1" ] || { echo &gt;&amp;2 ERROR: The input file does not exists. ; exit 1; }&lt;br /&gt;   TMPIN=$(mktemp)&lt;br /&gt;   # Remove blank lines and delete duplicates &lt;br /&gt;   sed '/^$/d' "$1"| sort -g | uniq &gt; "$TMPIN"&lt;br /&gt;   &lt;br /&gt;   NOW=$(date +"%Y-%m-%d-%X")&lt;br /&gt;   LOGFILE="AMU-log-$NOW.log"&lt;br /&gt;   &lt;br /&gt;   for user in $(more "$TMPIN"); do&lt;br /&gt;      # Checks if the user already exists.&lt;br /&gt;      cut -d: -f1 /etc/passwd | grep "$user" &gt; /dev/null&lt;br /&gt;      OUT=$?&lt;br /&gt;      if [ $OUT -eq 0 ];then&lt;br /&gt;   	 echo &gt;&amp;2 "ERROR: User account: \"$user\" already exists."&lt;br /&gt;	 echo &gt;&amp;2 "ERROR: User account: \"$user\" already exists." &gt;&gt; "$LOGFILE"&lt;br /&gt;      else&lt;br /&gt;	 # Create a new user&lt;br /&gt;         /usr/sbin/useradd -d "$PERS_HOME""$user" -s "$PERS_SH" -m "$user"&lt;br /&gt;	 # gpw must be installed on debian system&lt;br /&gt;	 pass=$(gpw 1 8)&lt;br /&gt;         echo $user:$pass | chpasswd&lt;br /&gt;	 # save user and password in a file&lt;br /&gt;	 echo -e $user"\t"$pass &gt;&gt; "$LOGFILE"&lt;br /&gt;	 echo "The user \"$user\" has been created and has the password: $pass"&lt;br /&gt;      fi&lt;br /&gt;   done&lt;br /&gt;   rm -f "$TMPIN"&lt;br /&gt;   exit 0&lt;br /&gt;else&lt;br /&gt;   echo &gt;&amp;2 "ERROR: You must be a root user to execute this script."&lt;br /&gt;   exit 1&lt;br /&gt;fi&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 13 Jan 2008 17:25:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4980</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
  </channel>
</rss>
