Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Deleting user accounts created directly in NetInfo' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Deleting user accounts created directly in NetInfo
Authored by: ssevenup on Jun 12, '03 12:52:11PM
This shell script will do it, and also find/kill all entries in groups.

#!/bin/sh

# Deletes users from commandline

NIUTIL="/usr/bin/niutil"
NIDUMP="/usr/bin/nidump"
CUT="/usr/bin/cut"
GREP="/usr/bin/grep"

if [ $USER != "root" ]; then
  echo "You must be root to execute this script."
  exit
fi

  echo -n "User to Destroy: "
  read uname
if [ "${uname}" = "root" ]; then
  echo "I wouldn't do that if I were you."
  exit
fi

if [ "${uname}" = "" ]; then
  echo "Please give me a valid username."
  exit
fi

if [ -z `NIDUMP passwd . | CUT -d: -f1 | GREP -x "${uname}"` ]; then
  echo "No such user found"
  echo ""
  exit 1
else
  NIUTIL -destroy . /users/"${uname}"
      declare -a gname
      gname=( `NIDUMP group . | GREP -w "${uname}" | cut -d: -f1` )
      while NIUTIL -destroyval . /groups/"${gname[0]}" users "${uname}" > /dev/null 2>&1
      do
        gname=( `NIDUMP group . | GREP -w "${uname}" | cut -d: -f1` )
        NIUTIL resync
      done
      echo "You may need to delete the home directory and symlinks"
      echo ""
fi

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.

[ Reply to This | # ]

Re:Deleting user accounts created directly in NetInfo
Authored by: kerbaugh on Jun 16, '03 07:09:29PM

Hi Mark,
   It may just be my browser, but aren't the dollar signs, "$" missing in front of all of the variables whose names are all in capital letters? By the way, while adherence to standards is generally lacking in the case of script return status, the correct code for ERROR_NON_ROOT_USER is 70, as in:

E_NON_ROOT_USER=70 # Must run as root.
ROOT_UID=0

if [ "$UID" -ne "$ROOT_UID" ]
then
   echo; echo "You must be root to run this script."; echo
   exit $E_NON_ROOT_USER
fi



[ Reply to This | # ]