Hi akabou!

On Sunday 21 Feb 2010 17:13:10 akabou wrote:
> Hello, everybody
> 
> I have a csv file with firstname, lastname, group
> 
> and need to create user and group if it doesn't exist.
> 

Please read the guidelines at:

http://perl.net.au/wiki/Freenode_Sharp_Perl_FAQ#How_should_I_write_my_code.3F

And then use a CSV parser:

http://search.cpan.org/dist/Text-CSV_XS/

Regards,

        Shlomi Fish

> But the problem is that i must not use useradd ou groupadd.
> 
> I must read user from csv, and then check if user exist, and if group
> exist.
> 
> i've started like this, but i don't know how to check if user exist,
> and group exist.
> 
> Here is the starting of my code.
> 
> $file = './liste_etudiants.csv';
> open (FICH,$file) ||die ("Fichier innexistant");
> 
> 
> 
> while ($line = <FICH>)
> {
>       #on splie chauqe ligne
>       ($field1,$field2,$field3) = split (',', $line);
>       #on  enlève le charcatère "
>       ($field1) =~ s/"//g;
>       ($field1) = substr($field1, 0, 1);
>       ($field2) =~ s/"//g;
>       ($field3) =~ s/"//g;
>       ($login) = $field1 . $field2;
>       print "$field1 : $field2 : $field3 -- le login sera login$login sera
> membre de $field3 \n";
> }
> 
> #ecrire dans un fichier
> #open(F_WRITE,">./touche.txt") || die "E/S : $!\n";
> #print $filed1;
> 
> close(FICH);
> 
> I wanted to test with tis kind of test
> 
>   open (FILE,"/etc/passwd");
>   while () {
>     chomp;
>     /^([a-z][a-z0-9]*):x:([0-9]+):([0-9]+):/;
>     #si le user id=user id dans le fichier on incrémante de 1 le uid
>     if ($2 == $uid) { $uid++; }
>   }
> 
> but don't know how.
> 
> I f someone could help me.

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to