I have a very basic script that was working fine on a RHEL server however when I try and use it on my Debian machine, I get errors. The script is bash and appears to be some what basic - I use it to create a user on my email server. The script basically gives the user an account, generates a home directory. When I run the script, I get the following error:
Code:
mail:/usr/bin# create-user.sh
----------------------------
User account created.
passwd: unrecognized option `--stdin'
Usage: passwd [options] [LOGIN]
Options:
-a, --all report password status on all accounts
-d, --delete delete the password for the named account
-e, --expire force expire the password for the named account
-h, --help display this help message and exit
-k, --keep-tokens change password only if expired
-i, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-l, --lock lock the named account
-n, --mindays MIN_DAYS set minimum number of days before password
change to MIN_DAYS
-q, --quiet quiet mode
-r, --repository REPOSITORY change password in REPOSITORY repository
-S, --status report password status on the named account
-u, --unlock unlock the named account
-w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
-x, --maxdays MAX_DAYS set maximim number of days before password
change to MAX_DAYS
USERNAME: testuser
FULL NAME: Test User
PASSWORD: user1234
So there appears to be some parameter in the script that it does not like:
Here is the script:
IDE_USERLIST_FILE=/usr/local/share/ide-userlist.txt
IDE_USERLIST=$(sort --field-separator=: ${IDE_USERLIST_FILE} | awk -F":" '{print $1}')
PREVIOUSDIR=$(pwd)
echo "----------------------------"
for u in $IDE_USERLIST; do
IDE_USERNAME=$u
IDE_FIRSTNAME=$(grep "^$IDE_USERNAME:" $IDE_USERLIST_FILE | awk -F":" '{print $2}')
IDE_LASTNAME=$(grep "^$IDE_USERNAME:" $IDE_USERLIST_FILE | awk -F":" '{print $3}')
IDE_LASTNAME_LC=$(echo $IDE_LASTNAME | tr '[:upper:]' '[:lower:]')
IDE_FULLNAME="$IDE_FIRSTNAME $IDE_LASTNAME"
IDE_SSN_DIGITS=$(grep "^$IDE_USERNAME:" $IDE_USERLIST_FILE | awk -F":" '{print $4}')
IDE_USER_EXISTS=$(grep -c "^$IDE_USERNAME:" /etc/passwd)
IDE_PASSWORD=$(echo $IDE_LASTNAME_LC$IDE_SSN_DIGITS)
#echo -e "USERNAME:\t$IDE_USERNAME"
#echo -e "FULL NAME:\t$IDE_FULLNAME"
#echo -e "PASSWORD:\t$IDE_PASSWORD"
if [ $IDE_USER_EXISTS -eq 0 ]; then
useradd -g users -d /home/$IDE_USERNAME -s /bin/false -c "$IDE_FULLNAME" $IDE_USERNAME && echo "User account created."
echo "$IDE_PASSWORD" | passwd $IDE_USERNAME --stdin
echo -e "USERNAME:\t$IDE_USERNAME"
echo -e "FULL NAME:\t$IDE_FULLNAME"
echo -e "PASSWORD:\t$IDE_PASSWORD"
else
echo "*** INFO: Doh! The user $IDE_USERNAME already exists! I WILL NOT create."
fi
echo "----------------------------"
done
history -c