Originally posted by: BriGy86
Originally posted by: DaiShan
from the man page of useradd '$man useradd'
NAME
useradd - Create a new user or update default new user information
SYNOPSIS
useradd [-c comment] [-d home_dir]
[-e expire_date] [-f inactive_days]
[-g initial_group] [-G group[,...]]
[[-M] -m [-k skeleton_dir]] [-o] [-p passwd]
[-s shell] [-u uid] login
/edit I'm partial to superadduser, it is an interactive method to add users (asks you the username the real name etc)
but i need this script to read a simple text file that has seperated fields and i need it to pick out a field and make a user name out of it, 5 times, all automaticly when the script is run
thats what i am confused about
im guessing i start this script with "read" or something like that, but other than that and using "useradd" im lost
(thank you for the response)
It'll probably be pretty simple. If you can give a sample of the text fileit would be easier to whip up a script that would actually work. If you give a few lines, even if the information has been changed to make it safe to post on the internet you'd probably have a few good suggestions in a short while.
Check out my sig the the linux document project's guides. They have a introduction to bash and then a advanced bash scripting guide.
In a Linux shell you'll have items like grep, awk, sed, and such for manipulating text. You can do text mangling with variables and such to do stuff like combining a first and the 3 first letters of the last name to generate a username that would be more unique.
Then there are the whole regular expressions for seperating out feilds of text and changing characters and whatnot. Although I think that with regular expressions it may be worth your while to take a look at perl.
Perl can be used in a command line or bash script in a similar manner to awk, grep, sed, but it can replace all those things. Similar syntaxes also since they all share a common background.
A simple way to filter out some stuff with awk...
Say you have a file with...
1:2:3:4:5
A:B:C:E
a:b:c:e
!:#:$:%:^
Say that is named "litter" and you want the 3rd feild and the 1st feild printed in that order.
So make the first line blank (I don't know why awk has this problem with the first line of input)
and go
cat litter | awk '{ FS=":" } { print $3" "$1 }'
Of course for something like this you'd want to make a actual script you can save and do testing to make sure that you have absolutely the correct output before making it so that it would run through a adduser or useradd script. All lower case letters and stuff like this.
If you want something very complex perl is good at text manipulations.