#!/bin/bash
#may 26 2006
passfile=test.txt
n=1
rm -rf go #delete any go file
echo "#!/bin/bash" >> go # prepare file to be as bash script file
for name in $(awk 'BEGIN {FS=":"}{print $1}' < "$passfile" ) #parse input file separated by :
do
array1[$n]=$name #and store them to arrays
let "n += 1" # grade 1
done # end of for loop
n=1
for name in $(awk 'BEGIN {FS=":"}{print $2}' < "$passfile" )
do
array2[$n]=$name
let "n += 1"
done
n=1
for name in $(awk 'BEGIN {FS=":"}{print $3}' < "$passfile" )
do
array3[$n]=$name
let "n += 1"
done
i=0
for ((i=1; i<n; i++))
do
echo ${array1[$i]} # prints username
echo ${array2[$i]} # as well as password
echo ${array3[$i]} # then comment name or ID name
echo "useradd -d /home/${array1[$i]} ${array1[$i]} -p ${array1[$i]} -s /bin/false -c ' ${array3[$i]} '" >> go
done
chmod 755 go # make it bash executable
./go # now execute it
exit 0
#############
comment:
customized input file: test.txt
contains:
uname:pword:Super_Man
test1:pword2:JOHN_TAMAD
test2:testpass2:testname2
test3:testpass3:testname3
***note of UNDERSCORE as Full Name field
output file: go (executable bash script)remarks: script will process input file, save output to output file and execute the output file
** user group were not included when adding
application:
reduced finger tiredness, copy and paste
0 comments:
Post a Comment