bash script for adding multiple users
hi all,
the first post wasnt complete so i edited it now. :) I have been given a task to write a script that will add a group of users from an input file. This shell script has to also provide some help information when users use a wrong command pattern. •If user start myaddusers incorrectly, i.e. without any parameters or too many parameters, the program should show the basic help for the user. For example, show the usage of command •If user type myaddusers –h, the program will give detailed information about the program and userlistfile structure. The userlist file is a text file, which contains the users’ details to create the accounts. The userlist file has the following structure. • Each line is a user record. • The record has 4 fields Username Password Groupname Fullname I have no idea where to start etc does anyone know where i can find simular script so i can make some changes to it ? thasnks a lot chris :confused: |
Welcome to LQ.
You probably want to start with somehitng like: Code:
#!/bin/bash |
I knew how to do this easily in PERL, but the challenge of doing it in bash was sweet, considering my bash skills are somewhat lacking. This should get you quite on your way to exactly what your need. Right now it will do everything your post required.
(it's kinda long, so I linked it) The script itself Some things to reference: Man page for groupadd Man page for useradd Man page for chfn (change full name) |
perl script doesn't work because of groups
That Perl script is pretty well-designed, but it doesn't work on Mandrake 9.2 and probably a lot of other distros. It assumes group names are in the file. Mandrake keeps groups in /etc/groups and uses and index number to reference them in /etc/passwd. Trying to add the groups using the -g also fails.
I'm too clumsy in Perl to improve on this script, but if someone else could modify it to utilize guids, that would be really damn cool. thanks, di11rod |
I'll take a gander at it in the morning. :) Should be just a matter of the user adding a switch (--guid) to tell it that the group listed in the INPUT file is already in numberic form, instead of named form.
|
All times are GMT -5. The time now is 01:50 PM. |