<?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 to modify a list of users in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112614#M91697</link>
    <description>Your biggest problem is probably a space between the -d and the comma in the cut command.&lt;BR /&gt;You also set up 'name' but use 'uid'&lt;BR /&gt;&lt;BR /&gt;Might I recommend testing scripts with 'echo' or 'print' in front of the command itself? That way you can try a few times until you get it right without creating damage.&lt;BR /&gt;&lt;BR /&gt;Personally I actually tend to prefer a (awk, perl, sh, dcl) script to generate the list of commands in a file, then review that, chmod +x and execute.&lt;BR /&gt;&lt;BR /&gt;One of many possible solutions based on your start:&lt;BR /&gt;&lt;BR /&gt;$ cat x&lt;BR /&gt;uid1, User Number 1&lt;BR /&gt;uid2, User Number 2&lt;BR /&gt;uid3, User Number 3&lt;BR /&gt;&lt;BR /&gt;$ cat x.sh&lt;BR /&gt;while read INPUTLINE&lt;BR /&gt;do&lt;BR /&gt;username=$(echo $INPUTLINE | cut -d, -f 1)&lt;BR /&gt;uid=$(echo $INPUTLINE | cut -d, -f 2)&lt;BR /&gt;echo usermod -c $username $uid&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;$ ./x.sh &amp;lt; x&lt;BR /&gt;usermod -c uid1 User Number 1&lt;BR /&gt;usermod -c uid2 User Number 2&lt;BR /&gt;usermod -c uid3 User Number 3&lt;BR /&gt;&lt;BR /&gt;And a solution along the lines of the other method I suggest, using awk:&lt;BR /&gt;&lt;BR /&gt;$ awk -F, '{print "usermod -c ", $1, $2}' x &amp;gt; todo&lt;BR /&gt;$ cat todo&lt;BR /&gt;usermod -c  uid1  User Number 1&lt;BR /&gt;usermod -c  uid2  User Number 2&lt;BR /&gt;usermod -c  uid3  User Number 3&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 05 Jun 2008 15:46:30 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2008-06-05T15:46:30Z</dc:date>
    <item>
      <title>script to modify a list of users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112613#M91696</link>
      <description>Hello, All -&lt;BR /&gt;&lt;BR /&gt;I need to modify a bunch of user accounts to add full names to their profiles.  I'm tyring to put something together that will let me read the username and full name in from a comma delimited file:&lt;BR /&gt;&lt;BR /&gt;uid1, User Number 1&lt;BR /&gt;uid2, User Number 2&lt;BR /&gt;uid3, User Number 3&lt;BR /&gt;&lt;BR /&gt;etc...&lt;BR /&gt;&lt;BR /&gt;The loop I've tried to create just hangs on me, and I know I'm missing something...probably a couple things.  I'm hoping someone can take a look at this and give me some pointers.  I'm really green with scripting...obviously.&lt;BR /&gt;&lt;BR /&gt;while read INPUTFILE&lt;BR /&gt;username=`echo $INPUTFILE | cut -d , -f 1`&lt;BR /&gt;name=`echo $INPUTFILE | cut -d , -f 2`&lt;BR /&gt;do&lt;BR /&gt;usermod -c $username $uid&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;"INPUTFILE" being the file with the usernames and full names.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Thu, 05 Jun 2008 15:23:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112613#M91696</guid>
      <dc:creator>JLee_1</dc:creator>
      <dc:date>2008-06-05T15:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: script to modify a list of users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112614#M91697</link>
      <description>Your biggest problem is probably a space between the -d and the comma in the cut command.&lt;BR /&gt;You also set up 'name' but use 'uid'&lt;BR /&gt;&lt;BR /&gt;Might I recommend testing scripts with 'echo' or 'print' in front of the command itself? That way you can try a few times until you get it right without creating damage.&lt;BR /&gt;&lt;BR /&gt;Personally I actually tend to prefer a (awk, perl, sh, dcl) script to generate the list of commands in a file, then review that, chmod +x and execute.&lt;BR /&gt;&lt;BR /&gt;One of many possible solutions based on your start:&lt;BR /&gt;&lt;BR /&gt;$ cat x&lt;BR /&gt;uid1, User Number 1&lt;BR /&gt;uid2, User Number 2&lt;BR /&gt;uid3, User Number 3&lt;BR /&gt;&lt;BR /&gt;$ cat x.sh&lt;BR /&gt;while read INPUTLINE&lt;BR /&gt;do&lt;BR /&gt;username=$(echo $INPUTLINE | cut -d, -f 1)&lt;BR /&gt;uid=$(echo $INPUTLINE | cut -d, -f 2)&lt;BR /&gt;echo usermod -c $username $uid&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;$ ./x.sh &amp;lt; x&lt;BR /&gt;usermod -c uid1 User Number 1&lt;BR /&gt;usermod -c uid2 User Number 2&lt;BR /&gt;usermod -c uid3 User Number 3&lt;BR /&gt;&lt;BR /&gt;And a solution along the lines of the other method I suggest, using awk:&lt;BR /&gt;&lt;BR /&gt;$ awk -F, '{print "usermod -c ", $1, $2}' x &amp;gt; todo&lt;BR /&gt;$ cat todo&lt;BR /&gt;usermod -c  uid1  User Number 1&lt;BR /&gt;usermod -c  uid2  User Number 2&lt;BR /&gt;usermod -c  uid3  User Number 3&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2008 15:46:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112614#M91697</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-06-05T15:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: script to modify a list of users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112615#M91698</link>
      <description>Why make it more complicated than it needs to be?&lt;BR /&gt;&lt;BR /&gt;Step 1 -- Omit the commas separating the data.&lt;BR /&gt;&lt;BR /&gt;Step 2 --&lt;BR /&gt;&lt;BR /&gt;while read UID USERNAME&lt;BR /&gt;do&lt;BR /&gt;echo ${UID}&lt;BR /&gt;echo ${USERNAME}&lt;BR /&gt;## usermod -c ${USERNAME} ${UID}&lt;BR /&gt;done &amp;lt; INPUTFILE&lt;BR /&gt;&lt;BR /&gt;That script will take the first field and assign it to UID and then take the rest of the line and assign it to USERNAME.  This depends on the file having everything separated by SPACES only though, hence my step 1 to remove the commas from the file.&lt;BR /&gt;&lt;BR /&gt;Once you are satisfied with the output from the echo statements, you can uncomment the usermod so it actually makes your changes.&lt;BR /&gt;&lt;BR /&gt;Much much easier than try to awk, cut, etc.</description>
      <pubDate>Thu, 05 Jun 2008 15:59:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112615#M91698</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2008-06-05T15:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: script to modify a list of users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112616#M91699</link>
      <description>&lt;!--!*#--&gt;Your "while read..." loop is trying to read from the standard input stream. &lt;BR /&gt;&lt;BR /&gt;In the "read INPUTFILE" command, INPUTFILE is the name of the variable where the result of the read operation is stored, not the name of the file the command is trying to read.&lt;BR /&gt;&lt;BR /&gt;The "do" line should come immediately after the "while" line. The "username=" and "name=" variable assignments should be in between the "do...done" pair.&lt;BR /&gt;&lt;BR /&gt;Your usermod command is a bit confused: it would try to store the value of the "username" variable as the real name of the user specified in the "uid" variable. But "uid" has not been defined yet, so the shell will replace it with an empty string, "".&lt;BR /&gt;&lt;BR /&gt;Your script with minimum necessary modifications:&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;    USERNAME=`echo "$LINE" | cut -d , -f 1`&lt;BR /&gt;    FULLNAME=`echo "$LINE" | cut -d , -f 2`&lt;BR /&gt;    usermod -c "$FULLNAME" "$USERNAME"&lt;BR /&gt;done &amp;lt; INPUTFILE&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Thu, 05 Jun 2008 16:03:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112616#M91699</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2008-06-05T16:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: script to modify a list of users</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112617#M91700</link>
      <description>Thanks a lot, guys - I appreciate the quick responses.  I ran through a couple of the suggested ways of writing it out and it's working well.  Much appreciated!</description>
      <pubDate>Thu, 05 Jun 2008 16:27:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-modify-a-list-of-users/m-p/5112617#M91700</guid>
      <dc:creator>JLee_1</dc:creator>
      <dc:date>2008-06-05T16:27:03Z</dc:date>
    </item>
  </channel>
</rss>

