home vs user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting home vs user
# 1  
Old 11-27-2008
home vs user

Hello,

I am trying to find out all users who still have a home dir but do not exist anymore in /etc/passwd file. Here is what I did but I am getting the opposit of what I want. Any suggestion?

Code:
for USAGERD in `find /home -type d -exec ls -d {} \;`
do
USAGER=${USAGERD##/*/}
USAGERT=${USAGERD##/*/}
        USAGER=$(cat /etc/passwd | grep ${USAGER})
                if [[ -n ${USAGER} ]]
                then
                    echo $USAGERT
                fi
done

# 2  
Old 11-27-2008
something like..
Code:
LIST=`grep home /etc/passwd | cut -d':' -f6 | cut -d/ -f3`
for I in `ls /home`; do
  echo $LIST | grep -q $I
  [ $? -eq 0 ] || ([ -d /home/$I ] && echo /home/$I )
done

not tested..
# 3  
Old 11-27-2008
Tks, but that is giving me exactlly the same as my script, I am looking for all home dir that do not have a user in /etc/passwd
# 4  
Old 11-27-2008
Quote:
Originally Posted by qfwfq
Tks, but that is giving me exactlly the same as my script, I am looking for all home dir that do not have a user in /etc/passwd
But that's exactly what the script produces, all dirs in .home that do not have an entry in /etc/passwd. I've tested it now Smilie
# 5  
Old 11-27-2008
Hi, maybe try another approach:

Code:
ls -1 /home|while read hd;do 
egrep ^$hd: /etc/passwd > /dev/null || echo Homedir $hd has no user
done

to me that reads: For each directory in /home, check if there is a corresponding line in /etc/passwd that starts with that directory name plus a colon.

/Lakris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Switching from root to normal user takes me to user's home dir

Whenever i switch from root to another user, by doing su - user, it takes me to home directory of user. This is very annoying as i want to be in same dir to run different commands as root sometimes and sometimes as normal user. How to fix this? (1 Reply)
Discussion started by: syncmaster
1 Replies

2. Solaris

Home Directory for oracle user

Hello all, I am Installing Oracle 11g on my Solaris OS. I created the below oracle user: # /usr/sbin/useradd -g oinstall -G dba oracle but when i am trying to to su - oracle it give me the below error No directory Do i have to setup a home directory for oracle user? and how can i do... (1 Reply)
Discussion started by: beayni33
1 Replies

3. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

4. Red Hat

User's home directory

Hi, By default user's home directory will be /home/$user. I want to change it to /javauser/$user. How can I do it? Thanks Jeevan. (5 Replies)
Discussion started by: jredx
5 Replies

5. AIX

/home belongs to a user?

While doing a "little" clean up job, i noticed something weird... A ls -altr of my / showed this: drwxr-xr-x 1549 johcham grands 102400 Jan 28 13:13 home How can a user become the owner / modify the group of my /home??? any thoughts? Can i chown this back to bin:bin (i think that... (2 Replies)
Discussion started by: Stephan
2 Replies

6. Shell Programming and Scripting

how to find out the home directory of a user??

Hi all, I would like to know how to find out the home directory of a particular user.. eg, If am the root , then my Home directory will be / if say am just a user logging into the terminal then my home dir would change, so accordingly i would like to know how to find it out... I know that... (7 Replies)
Discussion started by: wrapster
7 Replies

7. Solaris

need to restrict user to his home dir

Hello, i need to create a user who's access is restricted only to his home directory and below, i restricted his pty access by adding 'no-pty' to the options of the ssh key in authorized_keys file. However, sftp access still allows this user access to all my file system thanks (5 Replies)
Discussion started by: lidram
5 Replies

8. UNIX for Dummies Questions & Answers

Modify user home dir

I created a new user and assigned a certain home dir to tis user. I've noticed that this home dir (/export/home/test) is already assigned to other users. I really want to create a dedicated home dir for the new user. Can anyone tell me how I can modify this user with a new homedir? Thx for... (4 Replies)
Discussion started by: kris_devis
4 Replies

9. UNIX for Dummies Questions & Answers

Locking in user to $HOME

Is there a very easy and configurable method to lock a user into their home directory? I've checked on chroot() methodology.....but i'm not to excited about copying around ( or symlinking) libraries..binaries....etc. Thought about altering the groups via chgrp...to only allow read access to... (1 Reply)
Discussion started by: thomas.jones
1 Replies

10. UNIX for Dummies Questions & Answers

resrtrict user to his home directory

Hello How do i restrict a user only to his own directory so that he wont be able to cd to other directories. say for excample there is user called xiamin then xiamin should be restricted to /usr/xiamin only. i am on redhat linux regards Hrishy (4 Replies)
Discussion started by: xiamin
4 Replies
Login or Register to Ask a Question