Tech Support > Operating Systems > Linux / Variants > How to create many users per script???
How to create many users per script???
Posted by Tim Herty on September 30th, 2003


How would a script look like to create many user
from a file separated with commas like:

ben508,stupid,/home/ben058
ben509,butt,home/ben509


Posted by Ed Murphy on September 30th, 2003


On Wed, 01 Oct 2003 00:15:33 +0200, Tim Herty wrote:


ITYM "/home"

Anyway, 'man useradd' and 'man perlintro' and a bit of experimentation:

#!/usr/bin/perl

open(INFILE, "input.txt") or die "Can't open input.txt: $!";
open(OUTFILE, ">output.txt") or die "Can't open output.txt: $!";

while (<INFILE>) {
if ($_ =~ /^([^,]+),([^,]+),([^,]+)\n$/) {
print OUTFILE "useradd -d $3 -p $2 $1\n";
}
}


Posted by Raj Rijhwani on October 1st, 2003


On Wednesday, in article
<blcv9r$agtm4$1@ID-135726.news.uni-berlin.de>
tim.herty@online.de "Tim Herty" wrote:

If you wanted to do it purely in as a shell command, you would

cut -d':' -f 1,3,6 /etc/passwd | sed -e 's/:/,/'

Alternatively (and possibly more efficiently, though probably not for
something quite so simple) you could use awk:

awk 'BEGIN { FS=":"; } { printf "%s,%s,%s\n", $1, $3, $6; }' /etc/passwd
--
Raj Rijhwani | This is the voice of the Mysterons...
raj@rijhwani.org | ... We know that you can hear us Earthmen
http://www.rijhwani.org/raj/ | "Lieutenant Green: Launch all Angels!"