#24 Adding a User

There are lots of programs out there to add a user to a Unix or Linux system. Just fill in the blanks, click the Add button, and you're done. Why write a script to do it?

If you're adding one user, this script is useless. But if you have to add several thousand, it can be very useful as the back end to a much larger batch system. (For example, if you were working at a university, you could connect this script to one that reads a list of incoming students and creates accounts for them automatically.)

The Code

 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 use Fcntl ':flock'; # import LOCK_* constants 5 6 # The file we are going to change 7 my $pw_file = "/etc/passwd"; 8 my $group_file = "/etc/group"; 9 my $shadow_file = ...

Get Wicked Cool Perl Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.