<?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: Hep with user script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116594#M447072</link>
    <description>As to the original script question.  First, ensure /tmp/user doesn't have any system accounts in it (root, bin, sys, etc).  Also, verify that all fields are present:&lt;BR /&gt;&lt;BR /&gt;awk -F: '{print NF}' /tmp/user&lt;BR /&gt;&lt;BR /&gt;should show 7 for all lines of the file.&lt;BR /&gt;&lt;BR /&gt;awk -F: '{print $1, $2, $3, $4, $5, $6, $7}' /tmp/user | \&lt;BR /&gt;while read user pwd uid gid gecos home shell&lt;BR /&gt;do&lt;BR /&gt;  useradd -u ${uid} -g ${gid} -c "${gecos}' -d ${home} -m -s ${shell} ${user}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Node the quotes around ${gecos}.  That field will normally have spaces in it - hence the quotes.&lt;BR /&gt;&lt;BR /&gt;Also note that this command does not supply default passwords for the new accounts.  &lt;BR /&gt;&lt;BR /&gt;HTH;&lt;BR /&gt;&lt;BR /&gt;Doug</description>
    <pubDate>Mon, 30 Jun 2008 11:33:05 GMT</pubDate>
    <dc:creator>Doug O'Leary</dc:creator>
    <dc:date>2008-06-30T11:33:05Z</dc:date>
    <item>
      <title>Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116588#M447066</link>
      <description>I have users to move and all I was sent was a passwd file.&lt;BR /&gt;I have removed the : from the passwd file and I am trying to write a script to do a useradd.&lt;BR /&gt;My OS is HP-UX 11.23.  I have appx 50 users.&lt;BR /&gt;Here is my script. I am not much good at this.&lt;BR /&gt;Any Help?&lt;BR /&gt;Thanks&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;#read all the data in the file /tmp/user&lt;BR /&gt;while read data&lt;BR /&gt;do&lt;BR /&gt;#split the fields up&lt;BR /&gt;#first field&lt;BR /&gt;login=`echo $login | cut -d' ' -f1`&lt;BR /&gt;#second field onwards&lt;BR /&gt;passwd=`echo $passwd | cut -d' ' -f2-`&lt;BR /&gt;#3rd&lt;BR /&gt;uid=`echo $uid | cut -d' ' -f3-`&lt;BR /&gt;#4th&lt;BR /&gt;gid=`echo $gid | cut -d' ' -f4-`&lt;BR /&gt;#5th&lt;BR /&gt;comment=`echo $comment | cut -d' ' -f5-`&lt;BR /&gt;#6th&lt;BR /&gt;home=`echo $home | cut -d' ' -f6-`&lt;BR /&gt;#7th&lt;BR /&gt;shell=`echo $shell | cut -d' ' -f7-`&lt;BR /&gt;&lt;BR /&gt;useradd -u "$uid" -g "$gid" -d "$home" -s "$shell" -m -c "$comment" "$login"&lt;BR /&gt;done &amp;lt; /tmp/user</description>
      <pubDate>Mon, 30 Jun 2008 11:07:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116588#M447066</guid>
      <dc:creator>Mark Trux</dc:creator>
      <dc:date>2008-06-30T11:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116589#M447067</link>
      <description>You shouldn't remove the colons.  They help split it up easily using awk:&lt;BR /&gt;awk -F: '{print "useradd -u", $3, "-g", $4, "-d", $6, "-s", $7, "-m -c \"" $5 "\"", $1}' /etc/passwd &amp;gt; add_users&lt;BR /&gt;&lt;BR /&gt;If you are happy with the contents of add_users, you can use the shell to execute it:&lt;BR /&gt;# sh add_users</description>
      <pubDate>Mon, 30 Jun 2008 11:20:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116589#M447067</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-30T11:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116590#M447068</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;i didn't understand why you just don't edit /etc/passwd and add lines etc.?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Jun 2008 11:20:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116590#M447068</guid>
      <dc:creator>Kenan Erdey</dc:creator>
      <dc:date>2008-06-30T11:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116591#M447069</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;Editing the password file on most current UNIX operating systems is generally frowned upon.  Still possible, but not really a good idea.  &lt;BR /&gt;&lt;BR /&gt;The biggest reason, currently, is that most UNIX OSes have a shadow password file.  If you're using HPUX TCB, then the files are stashed under /tcb/files/auth/${initial}/${user}.  If you're using the shadow patch or solaris, the password files are under /etc/shadow.  &lt;BR /&gt;&lt;BR /&gt;useradd knows about the location of the encrypted passwords and updates the files appropriately.  If you edit the passwd file directly, you have to ensure the shadow file gets updated.  If you don't, or if you make a mistake, there's a chance no one will be able to log into the box - including root.  &lt;BR /&gt;&lt;BR /&gt;There's still times when it makes sense to edit the password file directly - but those times are fairly rare.&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Mon, 30 Jun 2008 11:25:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116591#M447069</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2008-06-30T11:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116592#M447070</link>
      <description>Thanks Dennis,&lt;BR /&gt;I have already removed the colons.&lt;BR /&gt;I will test what you sent me using the resulting file.&lt;BR /&gt;Each item is seperated by a space now&lt;BR /&gt;&lt;BR /&gt;Kenan,&lt;BR /&gt;I dont just add them for a couple of reasons.&lt;BR /&gt;1. This will come up again.&lt;BR /&gt;2. I want to make sure the home directories are created and the permissions are set (-m)&lt;BR /&gt;&lt;BR /&gt;Thanks to both of you for your input.&lt;BR /&gt;I wil post results.</description>
      <pubDate>Mon, 30 Jun 2008 11:29:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116592#M447070</guid>
      <dc:creator>Mark Trux</dc:creator>
      <dc:date>2008-06-30T11:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116593#M447071</link>
      <description>&amp;gt;I have already removed the colons.&lt;BR /&gt;&lt;BR /&gt;My awk program requires the colons, "-F:".</description>
      <pubDate>Mon, 30 Jun 2008 11:31:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116593#M447071</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-30T11:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116594#M447072</link>
      <description>As to the original script question.  First, ensure /tmp/user doesn't have any system accounts in it (root, bin, sys, etc).  Also, verify that all fields are present:&lt;BR /&gt;&lt;BR /&gt;awk -F: '{print NF}' /tmp/user&lt;BR /&gt;&lt;BR /&gt;should show 7 for all lines of the file.&lt;BR /&gt;&lt;BR /&gt;awk -F: '{print $1, $2, $3, $4, $5, $6, $7}' /tmp/user | \&lt;BR /&gt;while read user pwd uid gid gecos home shell&lt;BR /&gt;do&lt;BR /&gt;  useradd -u ${uid} -g ${gid} -c "${gecos}' -d ${home} -m -s ${shell} ${user}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Node the quotes around ${gecos}.  That field will normally have spaces in it - hence the quotes.&lt;BR /&gt;&lt;BR /&gt;Also note that this command does not supply default passwords for the new accounts.  &lt;BR /&gt;&lt;BR /&gt;HTH;&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Mon, 30 Jun 2008 11:33:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116594#M447072</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2008-06-30T11:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116595#M447073</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;You probably want to put the quotes back in. As I mentioned earlier, the gecos field will normally have spaces in it.  Since you're using spaces as your field separater, there's no way to identify where the gecos field starts or ends.&lt;BR /&gt;&lt;BR /&gt;It's much easier to use some type of field separator, :/|,!, soemthing, when mucking about with password file entries.&lt;BR /&gt;&lt;BR /&gt;Doug O'Leary</description>
      <pubDate>Mon, 30 Jun 2008 11:44:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116595#M447073</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2008-06-30T11:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116596#M447074</link>
      <description>&lt;!--!*#--&gt;Hi Mark:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I have already removed the colons.&lt;BR /&gt;&lt;BR /&gt;Then how do you plan to handle the GECOS field which *can* have embedded spaces?&lt;BR /&gt;&lt;BR /&gt;Removing the colon, which is the principal field delimiter complicates the processing you would need to do.&lt;BR /&gt;&lt;BR /&gt;If you don't like the 'awk' solution, you can do everything with a shell script, like:&lt;BR /&gt;&lt;BR /&gt;# cat dousers&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;OLDIFS=${IFS}&lt;BR /&gt;IFS=":"&lt;BR /&gt;echo "#!/usr/bin/sh" &amp;gt; userstoadd&lt;BR /&gt;while read NAME PASS UID GID GECOS HOMEDIR THESHELL&lt;BR /&gt;do&lt;BR /&gt;    echo useradd -u ${UID} -g ${GID} -c "\""${GECOS}"\"" -d ${HOMEDIR} -m -s ${THESHELL} ${NAME}&lt;BR /&gt;done &amp;lt; /etc/passwd &amp;gt; userstoadd&lt;BR /&gt;IFS=${OLDIFS}&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...When you are satisfied with the output file (named 'userstoadd'), make it executable and run it.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Jun 2008 11:54:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116596#M447074</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-30T11:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Hep with user script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116597#M447075</link>
      <description>Big Thanks&lt;BR /&gt;James, Doug and Dennis.&lt;BR /&gt;I did use the awk option.&lt;BR /&gt;I went back thru the file and did a global search and replace  :.&lt;BR /&gt;There were some isssues but I corrected them manually.&lt;BR /&gt;Now I know NOT to remove the : and/or keep an original.&lt;BR /&gt;&lt;BR /&gt;Great</description>
      <pubDate>Mon, 30 Jun 2008 11:58:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hep-with-user-script/m-p/5116597#M447075</guid>
      <dc:creator>Mark Trux</dc:creator>
      <dc:date>2008-06-30T11:58:25Z</dc:date>
    </item>
  </channel>
</rss>

