LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-23-2015, 05:41 AM   #1
zama
Member
 
Registered: Mar 2012
Posts: 34

Rep: Reputation: Disabled
Bash scripting: ignore delete of few user accounts during account removal process


We are a training institute providing training on Linux and C++ . We had around 100 students in a batch and for each of the user , a separate unix account is created.
After the batch completes , we need to remove all user accounts except few exceptions like faculty and technical staff accounts.

I already identified how to remove the user accounts but am worried how to ignore the user accounts of faculty and technical staff .

My command is as follows:

#UIDMAX will contain the minimum value used by OS for ID selection
UIDMIN=`grep "UID_MIN" /etc/login.defs`

#UIDMAX will contain the mixnimum value used by OS for ID selection
UIDMAX=`grep "UID_MAX" /etc/login.defs`

#echo $UIDMAX
#echo $UIDMIN


for i in ` awk -F: -v "min=${UIDMIN##UID_MIN}" -v "max=${UIDMAX##UID_MAX}" '{ if ( $3 >= min && $3 <=max ) print $1}' /etc/passwd`
do
userdel -r $i
done

Please suggest how to ignore faculty unix accounts so that they are ignored during the deletion process .

Last edited by zama; 02-23-2015 at 06:00 AM.
 
Old 02-23-2015, 07:50 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,797

Rep: Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775Reputation: 2775
oh the humanity

In the best of all worlds, you would have prepared ahead and installed your student accounts using a script and list file. That list file would provide a key into deleting only student accounts.

Failing the above, did you at least give your students and faculty different group membership? That would make this easy.

Failing ALL of the above, did you at least put faculty and student home folders in different trees?

As a last choice, can you list all of your faculty and staff IDs (of UIDs) and have your script do a fast find to skip those accounts?

Next time, plan ahead. This should be really easy, but not doing the preperation up front makes for a lot more hoop jumping at the end.
 
Old 02-23-2015, 07:58 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
maybe in /etc/passwd you can put a comment as to whether an account is a student or faculty. then it a simple if statement in a bash script could operate on the student accounts.
 
  


Reply

Tags
awk, bash, xargs


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The header line: how to add, delete and ignore it LXer Syndicated Linux News 0 09-23-2014 04:30 AM
How to edit PAM DB of VSFTPD (..add user, delete user, change user password ) jsaravana87 Linux - Server 1 10-02-2012 08:49 AM
Difference betwwen : Locked User Account & Disabled User Accounts in Linux ? avklinux Linux - Security 1 02-04-2009 02:30 PM
Delete user accounts v1nc3nt Linux - Newbie 2 05-23-2006 02:58 AM
How can I add new user accounts? Ausar Linux - Newbie 2 08-09-2004 11:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration