LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   A script for deleting user , if he has no login shell. (https://www.linuxquestions.org/questions/linux-newbie-8/a-script-for-deleting-user-if-he-has-no-login-shell-846506/)

meandsushil 11-25-2010 08:35 AM

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.

colucix 11-25-2010 08:54 AM

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!

GrapefruiTgirl 11-25-2010 08:55 AM

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?

TB0ne 11-25-2010 09:12 PM

Quote:

Originally Posted by meandsushil (Post 4170788)
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.

meandsushil 11-26-2010 09:51 AM

Het guys Sorry! My question is wrong!


All times are GMT -5. The time now is 05:02 PM.