A script for deleting user , if he has no login shell.
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.