Operating System - HP-UX
1829556 Members
1861 Online
109992 Solutions
New Discussion

Multiple Users Deletion Through Scripts

 
Ajin_1
Valued Contributor

Multiple Users Deletion Through Scripts

Hi Experts

I have a list of users to be deleted in a Server.
I have the file having the list of user list (For eg./tmp/userlist)
My requirement was the script that delete all the users in the specified file .
before that it will check the below points

weather the user in the list exixt or not
Home dir for that user found or not
any cron jobs shedule for the user

I also include the sample commands for that

grep xyz /etc/group  
grep xyz /etc/passwd the user must there else exit and print user not found.   
ls -ld /home/xyz..
grep xyz /var/adm/cron/cron.allow
ll /var/spool/cron/crontabs/ | grep xyz
crontab -l | grep /home/xyz

 

Thanks in Advance.

 

 

P.S. This thread has been moved from HP-UX > General to HP-UX > Languages - HP Forums Moderator

Thanks & Regards
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Multiple Users Deletion Through Scripts

>My requirement was the script that delete all the users in the specified file .

 

A skeleton script would be:

 

for user in $(< /tmp/userlist); do

   # Check existence

   id $user > /dev/null 2>&1

   if [ $? -ne 0 ]; then

      echo "User $user not found"

      continue

   fi

   # check home directory

   if [ ! -d $(eval echo ~$user) ]; then

      echo "User $user has no home directory"

   fi

   # check crontab

   fgrep -q -x $user /var/adm/cron/cron.allow

   if [ $? -eq 0 ]; then

      echo "User $user in /var/adm/cron/cron.allow"

   fi

   if [ -f  /var/spool/cron/crontabs/$user ]; then

      echo "User $user has a crontab"

   fi
   # ...

done