Results 1 to 2 of 2
I need to create a script that will list all the home directories of all currently logged on users. I have tried the following
$ cat /etc/passwd | awk -F: ...
- 05-07-2008 #1Just Joined!
- Join Date
- May 2008
- Posts
- 2
Home directories script
I need to create a script that will list all the home directories of all currently logged on users. I have tried the following
$ cat /etc/passwd | awk -F: '{print $1 "\t" $6}' | sort > user_store.txt
$ cat user_store.txt
This is supposed to save the first and sixth field in /etc/passwd (usually username and home directory) and then output it to the screen but having some problems.
Any help would be appreciated.
- 05-07-2008 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
I'm not at a Linux box but you will need to cross reference this with the who command for logged on users. Try this with a for loop to get it all done. This is just off the top of my head to get you started, I'd recommend reading up some of the man pages to get your further.
I haven't included sorting, just wanted to get you started. The tee command outputs to both screen and to the named file but I like to use it as it plays better with for loops than redirection.Code:for LOGIN in $(who |awk -F: '{print $1}' ) do grep $LOGIN /etc/password |awk -F: '{ print $1 \t $6 }' |tee user_store done


Reply With Quote