LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2010, 08:35 AM   #1
meandsushil
Member
 
Registered: Feb 2010
Posts: 143

Rep: Reputation: 14
A script for deleting user , if he has no login shell.


I want to create a script to delete user if he has no login shell.
 
Old 11-25-2010, 08:54 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Please, can you elaborate? What do you mean for "user that has no login shell"? All the system users (those one needed by some system services or specific applications) have no login shell. If you delete them, a lot of stuff will stop working!
 
Old 11-25-2010, 08:55 AM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Excellent! Where to begin?

Maybe use a shell loop, read the /etc/passwd file line by line, check the 7th field to see what shell it is, if any, and depending on which it is (or not), add the username (field #1 in the file) to a list (an array perhaps?) of "TO BE REMOVED" users. Once the passwd file has been processed, execute `userdel` on each of the usernames in your list of users to be removed.

Meanwhile, consider reporting your thread, and asking for a move to /Programming, if you agree it might be a better place for this topic.

Cheers & good luck!

OH and P.S. - colucix makes a VERY good point!! How will you know which users you can safely delete?

Last edited by GrapefruiTgirl; 11-25-2010 at 08:56 AM.
 
Old 11-25-2010, 09:12 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by meandsushil View Post
I want to create a script to delete user if he has no login shell.
Great...then please do so. Let us know if you have a specific question/problem. If not, feel free to reference the thousands of scripting tutorials you can find on Google.

Again, as with most of your threads, try providing some useful information, like what you want to write this in (BASH? Perl? Ruby? What??), and what parameters you want for the program. And again, post SPECIFIC questions...we aren't going to write the script for you.
 
Old 11-26-2010, 09:51 AM   #5
meandsushil
Member
 
Registered: Feb 2010
Posts: 143

Original Poster
Rep: Reputation: 14
Het guys Sorry! My question is wrong!
 
  


Reply



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
Shell script to automatically login through ssh and create user Sayan Acharjee Linux - General 10 10-21-2010 01:51 AM
Shell script deleting oracle backup? Mirge Programming 2 03-10-2010 01:21 PM
login as other user using shell doesn't load the profile for that user ukiome Linux - General 11 12-19-2009 05:56 AM
Simple Shell Script? Deleting Duplicate Files... Tag234 Linux - Newbie 6 10-10-2009 04:49 AM
Deleting a user and adding him again with same login arubin Slackware 2 04-30-2004 09:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:58 AM.

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