LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-16-2007, 11:24 PM   #1
klavuzkarga
LQ Newbie
 
Registered: Dec 2007
Posts: 11

Rep: Reputation: 0
bash - size of home directory


in my program i must find size of user's home directories. (including their subdirectories)

my friend told me that he used "size=du -cs $username" for this. But it doesn't work for me. what should i do?


*my program finds these users in my system;
user userid group id
root 0 0
bin 1 1
daemon 2 2
adm 3 4
lp 4 7
sync 5 0
shutdown 6 0
halt 7 0
mail 8 12
news 9 13
uucp 10 14
operator 11 0
games 12 100
gopher 13 30
ftp 14 50
nobody 99 99
rpm 37 37
dbus 81 81
avahi 70 70
rpc 32 32
mailnull 47 47
smmsp 51 51
nscd 28 28
vcsa 69 69
haldaemon 68 68
rpcuser 29 29
nfsnobody 65534 65534
sshd 74 74
netdump 34 34
pcap 77 77
xfs 43 43
beaglidx 58 58
ntp 38 38
apache 48 48
hsqldb 96 96
gdm 42 42
cumhur 500 500

*if i use "size=du -cs $username"; when my pc start running the program and gets to user "shutdown 6 0", it closes my computer :S
 
Old 12-16-2007, 11:43 PM   #2
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

Rep: Reputation: 71
why would you search for home directories for all of those users. Most of them don't have home directories as they are designed for daemons and whatnot. All users with home directories (other than root) should be under /home so you should just write the script to analyze those directories (probably skip ftp directory, etc if it is in there).
 
Old 12-17-2007, 12:13 AM   #3
klavuzkarga
LQ Newbie
 
Registered: Dec 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by shadowsnipes View Post
why would you search for home directories for all of those users. Most of them don't have home directories as they are designed for daemons and whatnot. All users with home directories (other than root) should be under /home so you should just write the script to analyze those directories (probably skip ftp directory, etc if it is in there).
because i have to use getpwent() function for getting the users.
and it gets all this users..?
 
Old 12-17-2007, 02:01 AM   #4
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Quote:
Originally Posted by klavuzkarga View Post
because i have to use getpwent() function for getting the users.
and it gets all this users..?
Are you writing in C? Here's a snippet of code letting you get the "real" users only, the ones that have a home directory under /home

Code:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>

int main()
{
  struct passwd pass, *ppointer;

  printf("Real users:\n\n");

  while(ppointer = getpwent())
    {
      pass = *ppointer;
      if(strstr(pass.pw_dir,"home"))
	printf("%s residing in %s\n", pass.pw_name, pass.pw_dir);
    }

  printf("\n");

  return 0;
}
 
Old 12-17-2007, 02:08 AM   #5
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

Rep: Reputation: 71
Quote:
Originally Posted by klavuzkarga View Post
because i have to use getpwent() function for getting the users.
and it gets all this users..?
Why do you have to use this function? If all the users (other than root) have their home directories under /home then all you have to do is du those directories. You don't need to bother using some other method to generate a list of users. You can get all the users names you are interested in (ones with home directories) by simply listing the directories in /home.

Am I misunderstanding what you are trying to accomplish?
 
Old 12-17-2007, 04:54 AM   #6
klavuzkarga
LQ Newbie
 
Registered: Dec 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by shadowsnipes View Post
Why do you have to use this function? If all the users (other than root) have their home directories under /home then all you have to do is du those directories. You don't need to bother using some other method to generate a list of users. You can get all the users names you are interested in (ones with home directories) by simply listing the directories in /home.

Am I misunderstanding what you are trying to accomplish?
it's an experiment for my school and there should be 2 c programs that will be called from bash script. one of these c programs use getpwnam other one uses getpwent. our teacher wants those :/ i cant decide

anyway thanks
 
Old 12-17-2007, 04:59 AM   #7
klavuzkarga
LQ Newbie
 
Registered: Dec 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Uncle_Theodore View Post
Are you writing in C? Here's a snippet of code letting you get the "real" users only, the ones that have a home directory under /home
thanks so you say, if there is "home" word in the user's current directory, then he is a valid user.

nice idea. i'll try that but as i said in older message; i think other users must be in my user list. :/

thanks
 
Old 12-17-2007, 04:59 AM   #8
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

Rep: Reputation: 71
I figured it must be for academic purposes because writing a C program to do that is overkill. It would be easiest just to write a short script.
 
Old 12-17-2007, 06:26 AM   #9
klavuzkarga
LQ Newbie
 
Registered: Dec 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by shadowsnipes View Post
I figured it must be for academic purposes because writing a C program to do that is overkill. It would be easiest just to write a short script.
yes it is and yes, it is an overkill

most of our experiments are like that
 
Old 12-17-2007, 06:58 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You might want to read section 29.13 in the libc manual. It covers the password related functions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH : Total directory size xgreen Programming 7 03-04-2013 06:33 AM
Home Directory Size? carlosinfl Linux - General 3 12-13-2005 02:04 PM
Limit Users Home Directory Size KrGAce Linux - Newbie 6 10-24-2005 10:48 AM
/home/directory size limit Smokey Slackware 2 11-04-2004 04:11 PM
How to LIMIT my HOME DIRECTORY SIZE??? juliann Linux - Networking 2 07-21-2004 10:08 AM


All times are GMT -5. The time now is 08:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration