- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to view all the users home directory size.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 11:43 AM
тАО05-21-2009 11:43 AM
# du -sk /home/*
343608 kchestnu/
47808 ke5qzf/
56 ke65a7/
16 ke980y/
1184 ke9isi/
201736 keane/
440 kegkmr/
161792 kets9t/
48 keyma9/
These names are the userid given for users.
Normally we are mentioning the usernames as comment when adding users.
Ex:
# vi /etc/passwd
root@lgapps:/emd/home > grep kchestnu /etc/passwd
kchestnu:blmfFX7fqGWms:1440:1003:Kenneth Chestnutt,,,:/emd/home/kchestnu:/usr/bin/sh
My customer wants a report based on Full username (comment name given in /etc/passwd file.)
is it possible.
how to get this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 11:51 AM
тАО05-21-2009 11:51 AM
Re: How to view all the users home directory size.
If all users are created using SAM Or a consistent set of scripts, this command will give you the actual user name:
cat /etc/passwd |while read line
do
uname=`echo $line|cut -d: -f1`
givenname=`echo $line|cut -d: -f5|cut -d"," -f1`
echo "$uname --> $givenname"
done
But again, since you can alter the gecos field with no effect on system performance, this might not work for all users. Use it at your own risk.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 12:03 PM
тАО05-21-2009 12:03 PM
Solutioncd /home
du -sk * | while read line
do
space=`echo $line | awk {'print $1'}`
uname=`echo $line |awk {'print $2'}
givenname=`grep ^${uname} /etc/passwd|cut -d: -f5|cut -d"," -f1`
echo "$space \t $givenname"
done
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 12:13 PM
тАО05-21-2009 12:13 PM
Re: How to view all the users home directory size.
# cat home-sizes.sh
#!/usr/bin/sh
export IFS=:
while read USER PASS UID GID GECOS HOMED SHELL
do
SIZE=$(du -ks ${HOMED})
echo "Size of ${GECOS} home directory - ${SIZE}"
done < /etc/passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2009 12:19 PM
тАО05-21-2009 12:19 PM
Re: How to view all the users home directory size.
(no points for this post please)
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2009 10:09 AM
тАО05-23-2009 10:09 AM
Re: How to view all the users home directory size.
Your second script is what i want.
Now i want one more thing to be added.
that some of my home folder is linked from another folder.
Ex:
root@lgapps:/home > ll -nd chobot
lrwxr-xr-x 1 0 3 18 Oct 20 2008 chobot -> /home/chobot
I want to add this link in fourth column.
is it possbile?
Now the is as following as per your script.
Ex:
208 xz4d64 S. Ostap
208 tzd33d Joe Hochstenbach
208 praval Pravin Raval
Now i want to add fourth column for linked directory if any.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2009 12:04 PM
тАО05-23-2009 12:04 PM
Re: How to view all the users home directory size.
You could do this to show the GECOS name and the HOME directory with any symbolic linkage:
# cat ./showids
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read USER PASS UID GID GECOS HOMED SHELL X
do
[ "${UID}" -le 100 ] && continue #...skip system accounts
[ "${HOMED}" = "/" ] && continue #...skip "/"
if [ -d "${HOMED}" ]; then
DIR=$(ls -ld ${HOMED} | awk '{if (NF>9) {print $9,$10,$11} else {print $9}}')
else
continue #...skip missing directories
fi
SIZE=$(du -ks ${HOMED} | awk '{print $1}')
printf "%6s %-8s '%-30s' [%s]\n" ${SIZE} ${USER} ${GECOS} ${DIR}
done < /etc/passwd
IFS=${OLDIFS}
exit 0
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2009 03:52 PM
тАО05-23-2009 03:52 PM
Re: How to view all the users home directory size.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1342062
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 04:36 AM
тАО05-26-2009 04:36 AM
Re: How to view all the users home directory size.
Actually we have created home directories for users in two different locations.
Some users are having their home directory in - /emd/home
And some others are having their home directory in - /eng/home.
Here i want to take the report of /emd/home only.
I am not capable to change your script.
So pls do make necessary changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 04:57 AM
тАО05-26-2009 04:57 AM
Re: How to view all the users home directory size.
> Here i want to take the report of /emd/home only. I am not capable to change your script.
You need to LEARN to be able to modify and create scripts to be a Unix administrator!
Look again at the script I offered you. Notice the line:
"${HOMED}" = "/" ] && continue #...skip "/"
This says to continue (or resume looping) if the ${HOMED} directory is a "/". The '&&" means if the test in square brackets is true, then execute what follows the '&&'.
From this you would know that you could add another line, like:
[ "${HOMED}" = "/emd/home" ] || continue
This variation says to coninue looping if the tested condition is NOT TRUE --- just what you want.
You could have written the last statement as:
if [ "${HOMED}" != "/emd/home" ]; then
continue
fi
...but that's a bit longer.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 05:12 AM
тАО05-26-2009 05:12 AM
Re: How to view all the users home directory size.
Try this simple for loop to get your desired output.
============================================
for i in `cat /etc/passwd |cut -d: -f6 |grep -i emd`
do
echo `grep $i /etc/passwd |cut -d: -f5`
du -sk $i |awk '{print $1}'
done
============================================
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 05:22 AM
тАО05-26-2009 05:22 AM
Re: How to view all the users home directory size.
If you need the username and home directory size both in same line, use like this.
============================================
for i in `cat /etc/passwd |cut -d: -f6 |grep -i emd`
do
username=`grep $i /etc/passwd |cut -d: -f5`
homespace=`du -sk $i |awk '{print $1}'`
echo "$username \t $homespace"
done
=============================================
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 05:35 AM
тАО05-26-2009 05:35 AM
Re: How to view all the users home directory size.
Still i am having problem.
pls give me the full script with necessary changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 05:41 AM
тАО05-26-2009 05:41 AM
Re: How to view all the users home directory size.
What problems are you having? Does this work for your needs?:
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read USER PASS UID GID GECOS HOMED SHELL X
do
# [ "${UID}" -le 100 ] && continue #...skip system accounts
# [ "${HOMED}" = "/" ] && continue #...skip "/"
[ "${HOMED}" = "/emd/home" ] || continue
if [ -d "${HOMED}" ]; then
DIR=$(ls -ld ${HOMED} | awk '{if (NF>9) {print $9,$10,$11} else {print $9}}')
else
continue #...skip missing directories
fi
SIZE=$(du -ks ${HOMED} | awk '{print $1}')
printf "%6s %-8s '%-30s' [%s]\n" ${SIZE} ${USER} ${GECOS} ${DIR}
done < /etc/passwd
IFS=${OLDIFS}
exit 0
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 05:52 AM
тАО05-26-2009 05:52 AM
Re: How to view all the users home directory size.
I am getting no output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 06:09 AM
тАО05-26-2009 06:09 AM
Re: How to view all the users home directory size.
> I am getting no output.
Yes, my mistake. You stated that you only want users in the _directory_ '/home/emd'. That is, you want subordinate entries only. If we assume that your directory structure looks like: '/home/emd/user1', '/home/emd/user2', etc. then use this:
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read USER PASS UID GID GECOS HOMED SHELL X
do
# [ "${UID}" -le 100 ] && continue #...skip system accounts
# [ "${HOMED}" = "/" ] && continue #...skip "/"
[ $(dirname "${HOMED}") = "/home/emd" ] || continue;
if [ -d "${HOMED}" ]; then
DIR=$(ls -ld ${HOMED} | awk '{if (NF>9) {print $9,$10,$11} else {print $9}}')
else
continue #...skip missing directories
fi
SIZE=$(du -ks ${HOMED} | awk '{print $1}')
printf "%6s %-8s '%-30s' [%s]\n" ${SIZE} ${USER} ${GECOS} ${DIR}
done < /etc/passwd
IFS=${OLDIFS}
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2009 06:31 AM
тАО05-26-2009 06:31 AM
Re: How to view all the users home directory size.
Here's a better (more flexible) variation for limiting your output to only users in the '/home/emd' directory. This handles accounts with HOME structures like '/home/emd/user1' and /home/emd/emdusers/user1' whereas my last post won't:
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read USER PASS UID GID GECOS HOMED SHELL X
do
# [ "${UID}" -le 100 ] && continue #...skip system accounts
# [ "${HOMED}" = "/" ] && continue #...skip "/"
echo "${HOMED}" | awk '/\home\/emd\// {exit 0};{exit 1}'
[ $? = 0 ] || continue;
if [ -d "${HOMED}" ]; then
DIR=$(ls -ld ${HOMED} | awk '{if (NF>9) {print $9,$10,$11} else {print $9}}')
else
continue #...skip missing directories
fi
SIZE=$(du -ks ${HOMED} | awk '{print $1}')
printf "%6s %-8s '%-30s' [%s]\n" ${SIZE} ${USER} ${GECOS} ${DIR}
done < /etc/passwd
IFS=${OLDIFS}
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 01:06 AM
тАО05-27-2009 01:06 AM
Re: How to view all the users home directory size.
My script in the link below can be changed to handle multiple paths:
Either pass them in the command line:
du -sk $* | ...
Or hard code them:
(cd /enmd/home; du -sk *) | ...
You can also change the awk script to only look at the basename of the directory.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1342062