<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: usermod code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:43:44 GMT</pubDate>
    <description>DZone Snippets: usermod code</description>
    <item>
      <title>Block many users in a system v0.1.1</title>
      <link>http://snippets.dzone.com/posts/show/5191</link>
      <description>Block many users in a 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;# BlockManyUsers.sh - Block many users in a 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;#   BlockManyUsers 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;#   BlockManyUsers 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" ];then&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="BMU-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;         # block selected user&lt;br /&gt;         /usr/sbin/usermod -L "$user"&lt;br /&gt;         # save user info in a file&lt;br /&gt;         echo The user \"$user\" has been blocked. &gt;&gt; "$LOGFILE"&lt;br /&gt;      else&lt;br /&gt;        echo &gt;&amp;2 Error the user account \"$user\" doesnt exists! &gt;&gt; "$LOGFILE"&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;exit 0&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 02 Mar 2008 14:23:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5191</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
  </channel>
</rss>
