Removing old user directories that are no longer Users in /etc/passwd
I am new to shell scripting, and have not done much programming in several years. So I am very rusty at this at best. I know my way around the linux command line, but actually scripting is something I have not done too much of.
I have been tasked to come up with a script that will pull all users from /etc/passwd. Then I need to find all the user directories in /home. If there is a user directory in /home that does not have a corresponding I need to delete that directory and everything in it.
I know I can use
To find all the users above userid 999.
I know
will pull up all the different user directories.
My thinking of how the script should logically run is something as follows.
Find all users in /etc/passwd above userid 999
find all users in /home
compare users in /home to users in /etc/passwd
remove all user directories in /home who are not in /etc/passwd
So any help with this would be greatly appreciated.
I'm worried about this 'greater than 999' requirement. It sounds backwards. Would it be okay to delete /home/root since root's uid is less than 999? Probably not.
I suspect you're supposed to consider the ownerships of the home directories themselves, right? Their UID's will be preserved even when the user's deleted.
Shell is bash. Systems are Redhat, Centos, and Ubuntu for testing.
Basically all the users would have had an userid starting at either 500 on the Redhat systems or 1000 on the Ubunutu systems. I was using the > 1000 to get rid of all the user accounts that are system accounts and such in /etc/passwd.
If there was a directory /home/root and there was not a user with a userid of root > 1000 then yes I would want to delete it.
Even if that means it belongs to root, uid 0, and removing that dir would prevent the administrator from logging in ever again? Some FTP daemons have a /home/ftp, and a UID less than 1000, that'd vanish too with unknown results.
I am starting to see your point. So I guess I should change it to I would like to remove all user directories in /home/ that have a uid > 1000 and are not also in /etc/passwd
I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Have an issue with a user or root changing the user's passwd.
We run the passwd command and a complex passwd is entered a message is displayed,
"passwd is based on a dictionary word."
We do have a dictionary file and I know for a fact the complex passwd is not in the list. This happens on a... (3 Replies)
Hi
Administering Solaris Systems - Solaris 10 mostly.
If I change the /etc/default/passwd settings - E.G. to increase minimum passwd length, then what happens to existing users with passwords shorter than this. presumably they are not affected until next time they want to change password.
... (4 Replies)
Besides doing some shell-script which loops through /etc/passwd, I was wondering if there was some command that would tell me, like an enhanced version of getent.
The Operating system is Solaris 10 (recent-ish revision) using Sun DS for LDAP. (5 Replies)
This command prints out username/users in /etc/passwd:
cut -d ':' -f '1,5' /etc/passwd | sort
I wonder if I also, after above commands output, can get an output that lists number of users in the group? I need to use uniq to get rid of duplicates.
I´ve tried this, but cant get it right, can... (5 Replies)
Hello everyone and let me start off by thanking anyone who can help with this.
I work for a company that uses Unix as one of their servers. I'm not at all familar with Unix beyond logging after I restart the server:rolleyes: I'm looking for some command that will bring me up a list of current... (3 Replies)
hi all,
i was given by my supervisor a task to search for scripts which contain oracle sqlplus i.e "myusername/mypasswd @myDB" in every /home/userfolder, which are, all the scripts made by different user. I've done some find command to search string for sqlplus, but it may up too long to respond.... (8 Replies)