You are not logged in.
I'm working through the ArchWiki Postfix Tutorial and am currently hung up on useradd command silently failling in the following bash script with:
sudo ./make_mailuser <username>
#!/bin/bash
# create a mail account
# Usage: ./make_mailuser <username>
ROOT_UID=0
ARGS=1
# Run as root, of course.
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
# Test if command line argument present (non-empty).
if [ -n "$1" ]
then
user=$1
echo "Create mail user $1"
else
echo "Usage: ./make_mailuser <username>"
fi
for name in $(awk 'BEGIN{FS=":"}{print $1}' < "/etc/passwd" | grep $user )
do
if [[ "${name}" -eq "${user}" ]]
then
echo "$name already exists"
useradd -G mail ${user}
######
# this useradd works as I expect, adding mail to a users groups
else
echo "Create user $user"
useradd -m -g mail -s /sbin/nologin ${user}
######
# this useradd fails silently
fi
done
cd /home/${user}
umask 077
mkdir -p Maildir/Inbox/{cur,new,tmp}
mkdir -p Maildir/Drafts/{cur,new,tmp}
mkdir -p Maildir/Sent/{cur,new,tmp}
mkdir -p Maildir/Trash/{cur,new,tmp}
chmod 0700 Maildir/Inbox/{cur,new,tmp}
chmod 0700 Maildir/Drafts/{cur,new,tmp}
chmod 0700 Maildir/Sent/{cur,new,tmp}
chmod 0700 Maildir/Trash/{cur,new,tmp}
chown -R ${user}:users *
running the command:
sudo useradd -m -g mail -s /sbin/nologin ${user}
in a term works just as expected - creates the user with membership of mail group and creates a home directory.
This has got me beaten, HELP please
Last edited by Cheifchimp (2010-05-11 01:47:57)
Offline
Is it working if running directly from root without any sudo?
Last edited by Coacher (2010-05-03 07:56:11)
/usr/bin/makepkg calls sudo within a bash script. Have a look.
Good ideas do not need lots of lies told about them in order to gain public acceptance.
Offline
Is it working if running directly from root without any sudo?
no, running the script from a root logon produces the same results
Offline
further investigation reveals the problem lies in the logic.
there is no need for any of the for/do/done part, dropped it and it all works
Offline