Quote:
Originally Posted by catkin
How does this break your existing script? I have sent the error messages to stderr instead of stdout as is usefully conventional and moved the exit message to just before the exit (else it lies and that can be confusing):
Code:
/opt/IDEALX/sbin/smbldap-passwd $USERNAME
if [ $? -ne 0 ] ; then
echo "Removing $USERNAME" >&2
/opt/IDEALX/sbin/smbldap-userdel -r $USERNAME
echo 'Exiting on error' >&2
exit 1
fi
It is easier to read code in CODE tags which can be used most easily in Advanced posting mode via the # button.
|
If I change my script to add the checks in bold everything works if you choose Default for the organizational unit, but if you choose EXAMPLE1 or example2 I get errors:
Which LDAP organizational container do you want to add the user to?
+ sleep 1
+ echo '(EXAMPLE1,example2,Default)'
(EXAMPLE1,example2,Default)
+ sleep 1
+ echo If you are unsure please enter Default for the LDAP organizational container.
If you are unsure please enter Default for the LDAP organizational container.
+ read organization
EXAMPLE1
+ [[ EXAMPLE1 = \E\X\A\M\P\L\E\1 ]]
+ echo Please assign a role to this account.
Please assign a role to this account.
+ /opt/IDEALX/sbin/smbldap-passwd tipp
/opt/IDEALX/sbin/smbldap-passwd: user tipp doesn't exist
+ '[' 10 -ne 0 ']'
+ echo 'exiting!!!!'
exiting!!!!
+ /opt/IDEALX/sbin/smbldap-userdel -r tipp
/opt/IDEALX/sbin/smbldap-userdel: user tipp does not exist
+ exit
New script
#!/bin/bash -x
TMPFILE=/db/backups/tmp-expire.ldif
TMPFILE2=/db/backups/tmp-expire-ou.ldif
TMPFILE3=/db/backups/variable3-ou.ldif
TMPFILE4=/db/backups/variable4-ou.ldif
echo Please enter the username you would like to add to LDAP!
read USERNAME
if getent passwd | grep -wq $USERNAME
then
echo $USERNAME already exists in the LDAP database!
exit
fi
echo Please enter the menu group to associate with this account!
sleep 1
echo "(guser1,guser2,gsuer3.guser4,guser5,guser6,guser7,guser8,guser9,gadmin,gsuper)"
read GUSER
if [[ "$GUSER" = guser* || "$GUSER" = "gadmin" || "$GUSER" = "gsuper" ]]; then
echo Which LDAP organizational container do you want to add the user to?
else
echo You entered an invalid group!!
exit
fi
sleep 1
echo "(EXAMPLE1,example2,Default)"
sleep 1
echo If you are unsure please enter Default for the LDAP organizational container.
read organization
if [[ "$organization" = "EXAMPLE1" || "$organization" = "example2" ]]; then
echo Please assign a role to this account.
elif [ "$organization" = "Default" ]; then
/opt/IDEALX/sbin/smbldap-useradd -G 1513,$GUSER,26 -s /bin/ksh -d /home/operations/$USERNAME -a $USERNAME
sleep 1
echo Setting the inital LDAP password for $USERNAME.
sleep 1
fi
/opt/IDEALX/sbin/smbldap-passwd $USERNAME
if [ $? -ne 0 ] ; then
echo exiting!!!!
/opt/IDEALX/sbin/smbldap-userdel -r $USERNAME
exit
fi
echo Enforcing password expiration upon first login!!!!!!
cat $TMPFILE | sed "s/USER/$USERNAME/g" /db/backups/tmp-expire.ldif > /db/backups/variable3.ldif
ldapadd -f /db/backups/variable3.ldif -x -D cn=root,dc=mdvcat,dc=lott -W
if [ $? -ne 0 ] ; then
echo exiting!!!!
/opt/IDEALX/sbin/smbldap-userdel -r $USERNAME
exit
else
echo Sucessfully added $USERNAME to the database!
exit
fi
sleep 1
echo "(admins,network,developers,vendors)"
read role
if [[ "$role" = "admins" || "$role" = "network" || "$role" = "developers" || "$role" = "vendors" ]]; then
/opt/IDEALX/sbin/smbldap-useradd -G 1513,$GUSER,26 -o $role,$organization -s /bin/ksh -d /home/operations/$USERNAME -a $USERNAME
sleep 1
echo Setting the inital LDAP password for $USERNAME.
sleep 1
/opt/IDEALX/sbin/smbldap-passwd $USERNAME
sleep 1
echo Enforcing password expiration upon first login!!!!!!
cat $TMPFILE2 | sed -e "s/USER/$USERNAME/g" /db/backups/tmp-expire-ou.ldif > /db/backups/variable3-ou.ldif
cat $TMPFILE3 | sed "s/role/$role/g" /db/backups/variable3-ou.ldif > /db/backups/variable4-ou.ldif
cat $TMPFILE4 | sed "s/organization/$organization/g" /db/backups/variable4-ou.ldif > /db/backups/variable5-ou.ldif
ldapadd -f /db/backups/variable5-ou.ldif -x -D cn=root,dc=mdvcat,dc=lott -W
else
echo You entered an invalid role!!!
exit
fi