Results 1 to 5 of 5
Thread: User Account Script
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
10-29-2003 #1
- Join Date
- Feb 2003
- Posts
- 56
User Account Script
Im trying to create regular user accounts from a text file. I have a text file with a list of users that need to be created. Can I use a script to do this? Thanks
-
10-30-2003 #2
- Join Date
- Apr 2003
- Location
- Sweden
- Posts
- 796
OK...lets say your list looks like this and are called users.txt and are located in /tmp do like this
File format:
Code:nisse1 user1 user2 user3 user4 user5 user6
Code:#!/bin/sh # # Creator:andutt@linuxforums.org # # Creates users from a file # FILE=/tmp/users.txt if [ ! -f $FILE ] then echo "ERROR $FILE doesnt exist.." exit 1 else echo "Creating user accounts from $FILE" fi USERS=`cat $FILE` for i in $USERS do echo "Creating user:$i" useradd -g users -m -c "Autocreated account $i" $i done echo echo "Usercreation is completed" echo
Regards
Andutt
-
10-30-2003 #3
- Join Date
- Aug 2001
- Location
- USA, Texas
- Posts
- 217
You still end up manually setting the passwords. That's the worst part.
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don\'t make me use it! */
-
11-01-2003 #4
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
That can be rather easily remedied, though.
Use an input file of this format instead:
Code:user1 pass1 user2 pass2 ...
Code:#!/bin/sh if [ $# -lt 1 ]; then echo "Usage: $0 [ -g grpname ] [ -r ] filename ..." >&2 exit 1 fi correct= group=users getpwd=y while [ $# -ge 0 ]; do o="$1" shift case "$o" in -g) group="$1" shift ;; -r) if [ -z "$getpwd" ]; then getpwd=y else getpwd= fi ;; *) correct=y if [ "$o" != - ]; then exec 3<"$o" else exec 3<&0 fi while :; do read username <&3 if [ -n "$getpwd" ]; then read password <&3 else password="$(dd bs=6 count=1 </dev/urandom 2>/dev/null | mimencode)" echo "$username $password" >>passwords fi if [ -z "$username" ]; then break; fi useradd -g "$group" -m "$username" passwd --stdin "$username" <<<"$password" done exec 3<&- ;; esac done if [ -z "$correct" ]; then echo "No users were created" >&2 fi
Code:awk '{if($1 == "thisschool") print $2;}' | ./genuser -g teachers teachers.in -g students -r -
-
11-05-2003 #5
- Join Date
- Feb 2003
- Posts
- 56
Script
Thanks a lot for your help, the scripts worked great.