How to use bash shell to create many users
How to use bash shell to create many users
Hi all, my name is Rick. I’m using red hat 9.0 Can somebody show me how to add many accounts by a bash script? I need to perform the following functions: 1) I have a file called userfile.txt. It contains new users’ information. The format is like this: Username:Password:groupname:fullname Example Mike:1234:IT:Mike White John:5732:Accounting:John Smith so on ... 2) I now need to create a shell script called:myscript , this script program will read the userfile.txt file and process the user account. 1.To use this program, user must type this command: “myscript userfile.txt”. If user does not type in this way, system will display the error message—“you type in wrong way !” 2.If people type in myscript –h, system will display some information to the users. |
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.
http://www.linuxquestions.org/rules.php |
it sounds like thats your homework boy!!!!!!!!!
anyway, sometime ago i needed to create aprox 40 acounts.... and i didnt know how to put the passwords in the 'useradd' command, by a script..... who knows?? |
This is a Perl script, so if you have Perl installed on your system it should work:
Quote:
Usage: perl myscript.pl <-h|userlist.txt> Sorry this script is so messy :( |
Quote:
Maybe u didn't check the man pages for useradd There is an option -p in useradd can be used .... Also check "man passwd", there is an option --stdin I suppose , Even this can be used... Welcome to LQ |
absolutely right man...
Linx2003, try to do it for your own.. all you need is to read the BASH Programing HOWTO.... you'll see that's pretty easy :P http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html |
The previous post of mine was intended for you also Claus.
Quote:
|
hi,
use the adduser with --stdin option to create a count with an uncrypted passwd. after that you have to crypt the passwd. this a small program in C to crypt a passwd: #include <unistd.h> #include <stdio.h> char *crypt(const char *key, const char *salt); //char *crypt(char *key, char *salt); int main(){ char passwd[20]; char key[]="mt"; // some couple of characters see man crypt char *crypted; crypted = new char [20]; printf ("\n enter password "); scanf("%s", passwd); crypted = crypt( passwd, key); printf ("\nthe passwd before is %s after is %s ", passwd, crypted); return(0); } to compile it, add the crypt library g++ crypt1.c -lcrypt best regards bela |
All times are GMT -5. The time now is 11:30 PM. |