[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Help with scripting

On Thu, Apr 07, 2005 at 04:01:00PM +0000, Joe wrote:
> Newbie question. I am running a system where users have various 
> directories in a tree structue which at some levels is predetermined 
> and at other levels is not .  What I need to do is work out how much 
> users are using thIs system.  I am not an adminstrator, but I run 
> this part of the system.   The tree structure is:
> /fix1/user1/fix2/user2/fix3
> where fix1 and fix3 are the same for all users, and fix2 can take 2 
> predetermined fixed values.  User1 is the user name and user2 is a 
> name the user determines (there can be unlimited numbers of these).
> I want to write some sort of a script that will work out the number 
> of user2 directories each user has, and the number of files each user 
> has. Files are only stored at the lowest directory level, ie, fix3.
> Can someone advise me where to start?  Shell script?  Awk?perl? 
> Etc.  And point me to useful documentation (and where to find it). 
> Many thanks! I've had a look at manual pages for awk and perl but I 
> need more of a beginners overview... And preferably some examples 
> reasonably close to the kind of thing I'm after.

This piece of code

for i in /fix1/*
	echo ${i#/fix1/}
	ls $i/fix2/|wc -l

gives you the number of files and directories in each /fix1/*/fix2.

This another

for i in /fix1/*
	echo $looser
	find /fix1/ -t f -user $looser | wc -l 

gives you how many regular files has each user in /fix1. You can also use
find /fix1/$looser/fix2 -user $looser
if you know every file belonging to user1 is in /fix1/user1/fix2

I advice you to read "Bash advanced scripting guide" and to google "Example
scripts" or something like that.  Man pages for awk, sed, find, grep and shell
are perhaps not very easy to read.
Or you can try

Have a funny scripting!!

Alberto Cabello Sánchez
Servicio de Informática
924 289 318

Reply to: