How To Do It Faster?!?

A

andrea_gavana

Hello Simo & NG,
Correct me if I'm wrong but since it _seems_ that the listing doesn't
need to be up-to-date each minute/hour as the users will be looking
primarily for old/unused files, why not have a daily cronjob on the
Unix server to produce an appropriate file list on e.g. the root
directory of your file server?

You are correct. I don't need this list to be updated every minute/hour.
$ find . -type f -printf "%T@ %u %s %p\n" > /yourserverroot/files.txt

That is a nice idea. I don't know very much about Unix, but I suppose that
on a ksh I can run this command (or a similar one) in order to obtain the
list I need. If anyone knows if that command will run also on a simple ksh,
could please confirm that?

Moreover, I could run this script in a while loop, like:

while 1:
do

if -e [/yourserverroot/filesbackup.txt];
then
find . -type f -printf "%T@ %u %s %p\n" > /yourserverroot/files.txt
copy /yourserverroot/files.txt /yourserverroot/filesbackup.txt
else
find . -type f -printf "%T@ %u %s %p\n" > /yourserverroot/filesbackup.txt
fi

done

or something similar (I don't have Unix at hand now, I can not test the
commands and, as I said, I don't know Unix very well...). In this way, I
always have the filesbackup.txt up-to-date, as a function of the "find"
speed on the server.
Then my GUI could scan the filesbackup.txt file and search for a particular
user information.

Thanks to all the NG for your suggestions!

Andrea.
 
S

Simo Melenius

That is a nice idea. I don't know very much about Unix, but I suppose that
on a ksh I can run this command (or a similar one) in order to obtain the
list I need. If anyone knows if that command will run also on a simple ksh,
could please confirm that?

That depends on the unix flavor you're using -- my example was for GNU
utilities which are heavily used on (probably all) Linux systems.
BSDs, Solaris and other unixen have slightly different 'find' syntax.
Use "man find" to find out more about how 'find' works on your system.

On all systems I know, it goes like:

find <directory> [-switches ...]

where the switches vary depending on the system. In my example, I used
-type f (f as in file) to only list files (otherwise 'find' will
include directories too in the output) and -printf to include desired
data -- in this case, owner, last modified time, size, path -- in the
output (otherwise 'find' will only print the path).

You should at least go through the -printf formatting codes to see
what information you're able to include in the output (=> man find).

I used %T@ to print the last modified time in Unix time because it's
as simple as it can be: an integer, counting the number of seconds
since Jan 1 1970. Python's "time" module groks Unix time just like
that.
Moreover, I could run this script in a while loop, like:

Except that, I'd imagine, constantly traversing the filesystem will
seriously degrade the performance of the file server. You want to run
your script periodically over a day, maybe at times when the server is
inactive. Or hourly between 8am-4pm and then once at night.

In Unix, there's a facility called cron to do just that, it runs
scripts and commands over and over again hourly, daily, weekly, or
just whenever you want it. Consult your unix flavor's manual or
newsgroup on that.
copy /yourserverroot/files.txt /yourserverroot/filesbackup.txt
always have the filesbackup.txt up-to-date, as a function of the "find"
speed on the server.

Yes, creating a temporary file is a good approach. I'd suggest moving
the new list over the old one (mv tmpfile filelist.txt) instead of
copying, since usually move is merely a rename operation on the
filesystem and doesn't involve actually copying of any data.


br,
S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top