LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 02-27-2010, 09:08 PM   #1
carlc1
LQ Newbie
 
Registered: Feb 2010
Posts: 12

Rep: Reputation: 0
Disk Utilization Script Help Needed


So here's the scenario -

I need to write a script to report useful information on disk utilization for each user's home directory.

For each directory I need to show:

1. the long listing of that directory entry (but not the files in the directory), so that I can see the rights and owners of the directory.

2. The amount of disk used by that directory, in human-readable format, including subdirectories.

I need to have two lines for each user one after the other. For example:
/home/user1 directory info
/home/user1 disk usage
/home/user2 directory info
/home/user2 disk usage

and so on.

The script will assume that all users, except user root, have their home directories in the /home directory (no need to do anything with the /etc/passwd file). And if the administrator adds or removes users, the script should still work correctly (so the script shows the information for all current users).

Here's what I do know. The command "ls -ld /home/user's_name" will give me the info I need for #1. And the command "du -hs" will give me the info I need for #2. What I don't know is how to grab each individual directory in order to apply the above commands to each of them in order. ???

Any insight on this problem would be greatly appreaciated. Thanks!
 
Old 02-28-2010, 12:16 AM   #2
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
Try this:

Quote:
ls -ld /home/* >> filename
du -hs /home/* >> filename
sort filename
It'll put the output in the file into an easy to read format

It isn't exactly what you want, but thats the best i can help!
 
Old 02-28-2010, 08:21 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,892
Blog Entries: 27

Rep: Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183
Hi,

So you've shown us your need! What's your deed?

We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist.

It does smell like homework to me.

Just a few links to aid you to gaining some understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Advanced Bash-Scripting Guide
Linux Home Networking


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 02-28-2010, 10:19 AM   #4
carlc1
LQ Newbie
 
Registered: Feb 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Actually, it's a peer challenge (and it's driving me nuts!). I can't figure out code to get my current users, and put them into a set of variables that I can work with. At least I'm assuming this is what I need to do.
 
Old 02-28-2010, 10:38 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Well--whatever it is--you still need to show us what you have tried. (did you try what leopard suggested? Was it useful? If not, what else was needed?)

By "current users", do you mean the ones logged in? Did you try the "users' command?
 
Old 02-28-2010, 12:50 PM   #6
carlc1
LQ Newbie
 
Registered: Feb 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the replies thus far. I've been trying various attempts with for loop logic, but have been coming up empty, until now I think. Here is what I currently have:

Code:
for i in /home/*
do
ls -ld $i
du -hs $i
done
Finally! But I still need to get the home directory for user root in here as well. Now I'm lost again. LOL, I'm guessing that for loop logic doesn't allow for multiple specified sets. Hmmm... Since we know the root user will always be there, maybe I can just tack on a simple statement above the for loop to operate on the root user folder. ???
 
Old 02-28-2010, 01:57 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by carlc1 View Post
I'm guessing that for loop logic doesn't allow for multiple specified sets.
Actually... yes. Every item separated by space or tab is part of the list to loop over. Since the "globbed" list is expanded before the loop is actually executed, you can add other items as well
Code:
for i in /home/* ~ /path/to/some/dir /root etc etc
 
Old 02-28-2010, 03:04 PM   #8
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
The unstated point made by colucix is that "root" does not have a home directory under /home. "root"'s home is /root.
 
Old 02-28-2010, 05:30 PM   #9
carlc1
LQ Newbie
 
Registered: Feb 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
Actually... yes. Every item separated by space or tab is part of the list to loop over. Since the "globbed" list is expanded before the loop is actually executed, you can add other items as well
Code:
for i in /home/* ~ /path/to/some/dir /root etc etc
Cool. I didn't realize that would work. LOL, now I can look smarter than I actually am. My original code was going to be:

Code:
ls -ld /root
du -hs /root

for i /home/*
do
   ls -ld $i
   du -hs $i
done
Now I can just do:

Code:
for i /home/* /root
do
   ls -ld $i
   du -hs $i
done
Hey, this linux stuff is pretty cool.
Thanks.
 
Old 02-28-2010, 06:54 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by carlc1 View Post
Hey, this linux stuff is pretty cool.
Yup!!
Remember:
First there was Unix
Then there were various unsuccessful experiments--VMS, DOS, AppleDOS, MacOS, Windows, etc.

Linux is really just a homecoming....
 
Old 02-28-2010, 07:32 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,262

Rep: Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440
Quote:
Originally Posted by pixellany View Post
Yup!!
Remember:
First there was Unix
Then there were various unsuccessful experiments--VMS, DOS, AppleDOS, MacOS, Windows, etc.

Linux is really just a homecoming....
I take exception to the VMS being unsuccessful. It was amazingly robust, and the VAX's were way ahead of their time. I remember back in 1989, having Ethernet interfaces that did channel bonding, full failover on hardware, clustering, etc., on boxes that were less than $50k...which in 1989 was pretty damned cheap. DEC didn't market things well. VMS still lives, too:

http://www.openvms.org/
 
Old 02-28-2010, 07:52 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Concur with TB0ne; especially clusters - too easy
 
Old 02-28-2010, 11:54 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
So noone jumped on Windows being an unsuccessful experiment..???

Sorry, I forgot to include the picture of my tonque in my cheek....
 
Old 03-01-2010, 09:53 AM   #14
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,892
Blog Entries: 27

Rep: Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183
Hi,

Quote:
Originally Posted by TB0ne View Post
I take exception to the VMS being unsuccessful. It was amazingly robust, and the VAX's were way ahead of their time. I remember back in 1989, having Ethernet interfaces that did channel bonding, full failover on hardware, clustering, etc., on boxes that were less than $50k...which in 1989 was pretty damned cheap. DEC didn't market things well. VMS still lives, too:

http://www.openvms.org/
I must agree whole heartily that VMS is a robust system. And that DEC didn't market well. Ah that sweet 11, I still have some memories that I've been trying to forget for years. I've got some old planes in the LAB just to remember those years. I'm sure if I still had a system and slapped them back in, the memory would be valid still.

Long wire differential channels with multiplex were the norm in the late 70s' & 80s' for most installations. Heck, shared memory was at the forefront with DEC. Then add the SMD (disk) systems and you had a system that could walk the talk.
 
Old 03-01-2010, 10:01 AM   #15
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
Quote:
Originally Posted by carlc1 View Post
Hey, this linux stuff is pretty cool.
Thanks.
I like being on a website where the majority of people would agree with that statement.

@pixellany:-

LoL.
 
  


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
Tracking down disk utilization tspang Solaris / OpenSolaris 3 02-20-2010 07:08 AM
High Disk Utilization help masenko703 Linux - Newbie 1 06-24-2009 12:40 AM
disk utilization ...? Ammad Linux - General 1 03-28-2009 09:35 AM
Hard Disk utilization gyropk Linux - Hardware 1 07-08-2008 02:15 PM
[SOLVED] Shell script to monitor or watch the disk space.... small help needed vikas027 Programming 5 10-21-2007 11:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:17 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