<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script fo creating multiple users in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170216#M61320</link>
    <description>#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;lastuid=$(cat /etc/passwd | cut -d: -f3 | tail -1)&lt;BR /&gt;for afile in $(cat /root/usrlist)&lt;BR /&gt;&lt;BR /&gt;do&lt;BR /&gt;       &lt;BR /&gt;lastuid++&lt;BR /&gt;useradd -u $lastuid -g 21 -d /home/$afile -s /bin/bash -p $afile $afile&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This is the script.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;C.Sacthivel</description>
    <pubDate>Fri, 17 Apr 2009 10:08:30 GMT</pubDate>
    <dc:creator>sacthivel.C</dc:creator>
    <dc:date>2009-04-17T10:08:30Z</dc:date>
    <item>
      <title>Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170214#M61318</link>
      <description>Dear all,&lt;BR /&gt;I am new to scripting.&lt;BR /&gt;My requirement is to create a script for creating multiple users in linux.&lt;BR /&gt;So i planned to append all the user login names in one file and call that file through the script.&lt;BR /&gt;But it is not possible for me to increment the UID.I attached here the script which i made.&lt;BR /&gt;Would some body help me to solve it?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;C.Sacthivel.&lt;BR /&gt;&lt;BR /&gt;(pls open the attachment in wordpad)&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 10:02:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170214#M61318</guid>
      <dc:creator>sacthivel.C</dc:creator>
      <dc:date>2009-04-17T10:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170215#M61319</link>
      <description>#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;lastuid=$(cat /etc/passwd | cut -d: -f3 | tail -1)&lt;BR /&gt;for afile in $(cat /root/usrlist)&lt;BR /&gt;&lt;BR /&gt;do&lt;BR /&gt;       &lt;BR /&gt;lastuid++&lt;BR /&gt;useradd -u $lastuid -g 21 -d /home/$afile -s /bin/bash -p $afile $afile&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This is the script.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;C.Sacthivel</description>
      <pubDate>Fri, 17 Apr 2009 10:08:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170215#M61319</guid>
      <dc:creator>sacthivel.C</dc:creator>
      <dc:date>2009-04-17T10:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170216#M61320</link>
      <description>#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;lastuid=$(cat /etc/passwd | cut -d: -f3 | tail -1)&lt;BR /&gt;for afile in $(cat /root/usrlist)&lt;BR /&gt;&lt;BR /&gt;do&lt;BR /&gt;       &lt;BR /&gt;lastuid++&lt;BR /&gt;useradd -u $lastuid -g 21 -d /home/$afile -s /bin/bash -p $afile $afile&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This is the script.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;C.Sacthivel</description>
      <pubDate>Fri, 17 Apr 2009 10:08:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170216#M61320</guid>
      <dc:creator>sacthivel.C</dc:creator>
      <dc:date>2009-04-17T10:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170217#M61321</link>
      <description>Hi Sacthivel,&lt;BR /&gt;&lt;BR /&gt;You don't need to specify the UID argument for useradd command. &lt;BR /&gt;&lt;BR /&gt;by default useradd command will take the next unused UID for the new user if you don't specifed.</description>
      <pubDate>Fri, 17 Apr 2009 10:48:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170217#M61321</guid>
      <dc:creator>Ganesan R</dc:creator>
      <dc:date>2009-04-17T10:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170218#M61322</link>
      <description>Hi Sacthivel,&lt;BR /&gt;&lt;BR /&gt;One more thing I want to ask you..&lt;BR /&gt;&lt;BR /&gt;lastuid=$(cat /etc/passwd | cut -d: -f3 | tail -1)&lt;BR /&gt;&lt;BR /&gt;This variable take the last entry UID value from /etc/passwd. But how can be make sure that this value is lowest UID in /etc/passwd file. It is always possible that higher UID's exist in passwd file.&lt;BR /&gt;&lt;BR /&gt;Other thing is, lastuid++ won't work in shell script. Instead you can manually increament the value inside the loop like this&lt;BR /&gt;&lt;BR /&gt;lastuid=`expr $lastuid + 1`&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Apr 2009 11:07:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170218#M61322</guid>
      <dc:creator>Ganesan R</dc:creator>
      <dc:date>2009-04-17T11:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170219#M61323</link>
      <description>&lt;!--!*#--&gt;try something like this:&lt;BR /&gt;&lt;BR /&gt;##### START OF CODE #####&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;while read username group gecos&lt;BR /&gt;do&lt;BR /&gt;    grep -q "^${group}:" /etc/group&lt;BR /&gt;    if [ $? -eq 0 ]; then&lt;BR /&gt;        useradd -g ${group} -m -d /home/${username} -c ${gecos} -s /bin/bash ${user}&lt;BR /&gt;    else&lt;BR /&gt;        echo "No such group: ${group}"&lt;BR /&gt;        echo "User skipped"&lt;BR /&gt;    fi&lt;BR /&gt;done &amp;lt; userlist&lt;BR /&gt;&lt;BR /&gt;##### END OF CODE #####&lt;BR /&gt;&lt;BR /&gt;in the 'userlist' file you should include all the users to add, in the following format: (one line per user)&lt;BR /&gt;&lt;BR /&gt;- first field is the users login name&lt;BR /&gt;- second field is the primary group&lt;BR /&gt;- the other fields starting from 3 will be the GECOS (comment) field in the /etc/passwd, containing the users real name, etc...&lt;BR /&gt;&lt;BR /&gt;Sample:&lt;BR /&gt;&lt;BR /&gt;user1 group1 Joe Hedgehog&lt;BR /&gt;tim groupoftim Tim the bartender&lt;BR /&gt;jim defaultgroup Jim Bo&lt;BR /&gt;&lt;BR /&gt;PS:I'm not sure if the group existence should be checked or the useradd command will skip by itself. Currently I don't have access to a linux machine.</description>
      <pubDate>Sat, 18 Apr 2009 13:31:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170219#M61323</guid>
      <dc:creator>Viktor Balogh</dc:creator>
      <dc:date>2009-04-18T13:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170220#M61324</link>
      <description>Dear All,&lt;BR /&gt;Thanks for every body for answering my forum and particularly to Mr Ganesan.&lt;BR /&gt;My requirement is that i have to create users with same group id and same shell.&lt;BR /&gt;&lt;BR /&gt;So i put the below script.&lt;BR /&gt;&lt;BR /&gt;####################################&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;cat /etc/passwd | cut -d: -f1 &amp;gt; exi.users&lt;BR /&gt;grep -vf exi.users new.users &amp;gt; usrlist&lt;BR /&gt;&lt;BR /&gt;for afile in $(cat /root/users/usrlist)&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;useradd -g 21 -d /home/$afile -s /bin/bash $afile&lt;BR /&gt;passwd $afile&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;###################################&lt;BR /&gt;&lt;BR /&gt;1.first of all i am getting the existing users list and append it to the file named "exi.users"&lt;BR /&gt;2.I asked the users to add their login names to the file named "new.users"&lt;BR /&gt;3.After that i am comparing both the files and append it's output to a file called "usrlist".&lt;BR /&gt;&lt;BR /&gt;Then the remaining procedure is same.&lt;BR /&gt;&lt;BR /&gt;Once again thank you for both of them.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;C.Sacthivel</description>
      <pubDate>Tue, 21 Apr 2009 03:12:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170220#M61324</guid>
      <dc:creator>sacthivel.C</dc:creator>
      <dc:date>2009-04-21T03:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Script fo creating multiple users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170221#M61325</link>
      <description>Thanks a lot once again.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;C.Sacthivel</description>
      <pubDate>Tue, 21 Apr 2009 03:13:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-fo-creating-multiple-users/m-p/5170221#M61325</guid>
      <dc:creator>sacthivel.C</dc:creator>
      <dc:date>2009-04-21T03:13:09Z</dc:date>
    </item>
  </channel>
</rss>

