LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 08: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-27-2010, 11:16 PM   #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, 07:21 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
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, 09: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, 09:38 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 11:50 AM   #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, 12:57 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 02:04 PM   #8
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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, 04: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, 05:54 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 06:32 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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, 06:52 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Concur with TB0ne; especially clusters - too easy
 
Old 02-28-2010, 10:54 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 08:53 AM   #14
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
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, 09: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



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 06:08 AM
High Disk Utilization help masenko703 Linux - Newbie 1 06-23-2009 11:40 PM
disk utilization ...? Ammad Linux - General 1 03-28-2009 08:35 AM
Hard Disk utilization gyropk Linux - Hardware 1 07-08-2008 01:15 PM
[SOLVED] Shell script to monitor or watch the disk space.... small help needed vikas027 Programming 5 10-21-2007 10:04 AM

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

All times are GMT -5. The time now is 11:07 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
Open Source Consulting | Domain Registration