python vs awk for simple sysamin tasks
Roy Smith
roy at panix.com
Thu Jun 3 10:45:13 EDT 2004
In article <c9ncn1$cn3$1 at coward.ks.cc.utah.edu>,
Matthew Thorley <ruach at chpc.utah.edu> wrote:
> My friend sent me an email asking this:
>
> > I'm attemtping to decide which scripting language I should master and
> > was wondering if it's possible to do
> > these unixy awkish commands in python:
> >
> > How to find the amount of disk space a user is taking up:
> >
> > find / -user rprice -fstype nfs ! -name /dev/\* -ls | awk '{sum+=$7};\
> > {print "User rprice total disk use = " sum}'
> >
> > How to find the average size of a file for a user:
> >
> > find / -user rprice -fstype nfs ! -name /dev/\* -ls | awk '{sum+=$7};\
> > {print "The ave size of file for rprice is = " sum/NR}'
>
> I wasn't able to give him an afirmative answer because I've never used
> python for things like this. I just spent the last while looking on
> google and haven't found an answer yet. I was hoping some one out there
> might have some thoughts ?
>
> thanks much
> -matthew
Neither of these are really tasks well suited to python at all.
I'm sure you could replicate this functionality in python using things
like os.walk() and os.stat(), but why bother? The result would be no
better than the quick on-liners you've got above. Even if you wanted to
replace the awk part with python, the idea of trying to replicate the
find functionality is just absurd.
I'm sure you could replicate them in perl too, but the same comment
applies. Find is an essential unix tool. If you're going to be doing
unix sysadmin work, you really should figure out how find works.
More information about the Python-list
mailing list