<?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: useradd in perl script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262099#M659891</link>
    <description>thanks. the line should be ended with ":" in the testfile, then the useradd command is one line and runs with no issue.</description>
    <pubDate>Tue, 09 Nov 2010 16:18:20 GMT</pubDate>
    <dc:creator>John Guster</dc:creator>
    <dc:date>2010-11-09T16:18:20Z</dc:date>
    <item>
      <title>useradd in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262096#M659888</link>
      <description>why the command is broke into second line starting at -s option? here is the script:&lt;BR /&gt;#!/usr/bin/perl &lt;BR /&gt;open(fh, "&lt;TESTFILE&gt;&lt;/TESTFILE&gt;foreach $line (&lt;FH&gt;) {&lt;BR /&gt;@line=split(':', $line);&lt;BR /&gt;print "$line[0]\n";&lt;BR /&gt;print "$line[1]\n";&lt;BR /&gt;print "$line[2]\n";&lt;BR /&gt;$cmd1="/usr/sbin/useradd -u $line[1] -c $line[2] -s /bin/bash -g users -m $line[0]";&lt;BR /&gt;print "$cmd1\n";&lt;BR /&gt;if (system($cmd1)) {print "failed\n";}&lt;BR /&gt;}&lt;BR /&gt;close(fh);&lt;BR /&gt;&lt;BR /&gt;here is the testfile:&lt;BR /&gt;#cat testfile&lt;BR /&gt;#login-name:uid:comment&lt;BR /&gt;testid:12345:test1-account&lt;BR /&gt;&lt;BR /&gt;here is the output after run the script:&lt;BR /&gt;# ./test-perl.pl&lt;BR /&gt;testid&lt;BR /&gt;12345&lt;BR /&gt;test1-account&lt;BR /&gt;&lt;BR /&gt;/usr/sbin/useradd -u 12345 -c test1&lt;BR /&gt; -s /bin/bash -g users -m nm12345&lt;BR /&gt;usage: useradd  [-u uid [-o]] [-g group] [-G group,...] &lt;BR /&gt;                [-d home] [-s shell] [-c comment] [-m [-k template]]&lt;BR /&gt;                [-f inactive] [-e expire ] [-p passwd] [-M] [-n] [-r] name&lt;BR /&gt;       useradd  -D [-g group] [-b base] [-s shell]&lt;BR /&gt;                [-f inactive] [-e expire ]&lt;BR /&gt;sh: line 2: -s: command not found&lt;BR /&gt;failed&lt;BR /&gt;&lt;BR /&gt;Any suggestions? Thank you.&lt;/FH&gt;</description>
      <pubDate>Tue, 09 Nov 2010 15:35:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262096#M659888</guid>
      <dc:creator>John Guster</dc:creator>
      <dc:date>2010-11-09T15:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: useradd in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262097#M659889</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;You need to quote the gecos field in the system call that calls userad.  &lt;BR /&gt;&lt;BR /&gt;currently, useradd sees test-account, sees the '-' and assumes another argument.&lt;BR /&gt;&lt;BR /&gt;Additionally, more often than not, gecos fields have spaces in them, so you'll want to quote the entry for that as well:&lt;BR /&gt;&lt;BR /&gt;$cmd1="/usr/sbin/useradd -u $line[1] -c \"$line[2]\" -s /bin/bash -g users -m $line[0]";&lt;BR /&gt;&lt;BR /&gt;HTH;&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Tue, 09 Nov 2010 15:48:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262097#M659889</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2010-11-09T15:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: useradd in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262098#M659890</link>
      <description>ah, there it is.&lt;BR /&gt;&lt;BR /&gt;My first post is wrong... well, it's right in that you want to quote the gecos field, but wrong in the reason for your issue.&lt;BR /&gt;&lt;BR /&gt;The issue is that you're reading the line from your text file, including the new line.  So, basically, your testid's gecos field isn't:&lt;BR /&gt;&lt;BR /&gt;test1-account&lt;BR /&gt;&lt;BR /&gt;it is, in fact:&lt;BR /&gt;&lt;BR /&gt;test1-account\n&lt;BR /&gt;&lt;BR /&gt;that's getting added to your system command such that:&lt;BR /&gt;&lt;BR /&gt;$cmd = &lt;BR /&gt;useradd -u 12345 -c test1-account\n -s /bin/bash ... [snip]&lt;BR /&gt;&lt;BR /&gt;that's easy to get rid of:&lt;BR /&gt;&lt;BR /&gt;foreach $line (&lt;FH&gt;) {&lt;BR /&gt;chomp $line   # removes the newline&lt;BR /&gt;@line=split(':', $line);&lt;BR /&gt;&lt;BR /&gt;HTH;&lt;BR /&gt;&lt;BR /&gt;Doug&lt;/FH&gt;</description>
      <pubDate>Tue, 09 Nov 2010 15:54:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262098#M659890</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2010-11-09T15:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: useradd in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262099#M659891</link>
      <description>thanks. the line should be ended with ":" in the testfile, then the useradd command is one line and runs with no issue.</description>
      <pubDate>Tue, 09 Nov 2010 16:18:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262099#M659891</guid>
      <dc:creator>John Guster</dc:creator>
      <dc:date>2010-11-09T16:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: useradd in perl script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262100#M659892</link>
      <description>Hi John:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; the line should be ended with ":" in the testfile, then the useradd command is one line and runs with no issue.&lt;BR /&gt;&lt;BR /&gt;That's a kludge that causes an additional (albeit empty) field to be created.  Doug was correct, you needed to 'chomp' the newline from each input line read.  Consider the '/etc/passwd' file --- while colon delimited, there is no trailing delimiter following the login program field.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 09 Nov 2010 19:18:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/useradd-in-perl-script/m-p/5262100#M659892</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-11-09T19:18:57Z</dc:date>
    </item>
  </channel>
</rss>

