1)
this will only work when about.txt is in the current directory. You can also use bash
here document here
Code:
cat <<- END_OF_DOCUMENT
text ...
END_OF_DOCUMENT
2)
Code:
sed 's/':'/ /g' $1 >list_user.txt
You can't do this with
sed.
sed will search for the file
$1 and try to read it. To pass string to sed, use either
echo,
Code:
echo "$1" | sed '...'
or
here string
3)
Code:
cat list_user.txt | while read uname password gname fullname
So, you write the argument into file and then read it again? May I ask why?
Also, why the loop? The file will only contain one line.
4)
Code:
LEN=$(echo ${#password})
OK, why the
echo? Why don't you just write
5)
Code:
if [[( $LEN -lt 9) || ($LEN -gt 12)]] ; then echo "..."
...
fi
You can also use bash arithmetics:
Code:
if (( (LEN < 9) || (LEN > 12) )); then
...
fi
or even
Code:
(( (LEN < 9) || (LEN > 12) )) && (echo ""; continue)
fi
6)
Code:
useradd -p "$pass" -g "$gname" -c "$fullname" $uname
uid=$(grep -i ${uname} /etc/passwd | cut -d: -f3)
gid=$(grep -i ${uname} /etc/passwd | cut -d: -f4)
if [ $? -eq 0 ];then
...
# if the useradd cmd executed succesfully then userdetails are redirected to userdetails.txt
No, actually the assignments will overwrite the exit status of useradd.
7) try to run your script with
-x switch
8) did you look into your log file?