my adding user script seems weird and buggy
Hi all,
i'm writing a piece of code to perform the process of adding users script, however i have encountered some problems that i can not solve, can anyone give me some hints on this code.
1. when i read in the names from the file, it will read in all the first name and then read in all the last names, so it will display something like: f1 f2 f3l1 l2 l3 instead of
f1l1
f2l2
f3l3
2. is there a more clever way to convert capital letters into small letters, right now it's working fine, but if i wanted to make it to convert the username into small letters in the ealier stage it does not work, and if i want to put all the data into one line, the line will not be displayed. And the following is my code.
This is my scriptFile
--------------------------------------------------------------------------------
#!/bin/sh
# Test to see if the userDataBaseFile exists and there should only one argument after the scriptFile
# eg: correct format : scriptFile userDataBaseFile
if [ $# = 0 ] || [ $# -ge 2 ] || [ ! -f $1 ]
then
echo Error: Problem with the command line argument
# If there are no errors the program will continue
else
for line in `cat $1`;
do
first=`cat $1 | cut -c1`
last=`cat $1 | cut -f1 -d "," | cut -f2 -d " " | cut -c1-7`
gecos=`cat $1 | cut -f1 -d ","`
username=$first$last
echo "gecos = "$gecos
echo "username = "$username | tr '[:upper:]' '[:lower:]'
echo "home directory = "/home/$username | tr '[:upper:]' '[:lower:]'
done
fi
-------------------------------------------------------------------------------
This is the content in my userDatafile, which is $1
John Smith,100,/bin/bash
Harry Potter,101,/bin/sh
Johnny Wilkinson,102/bin/csh
Edit: moved to the Programming forum
Last edited by mcleodnine; 10-21-2003 at 02:32 AM.
|