UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 28th, 2005, 11:03 AM
dx6490dude dx6490dude is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 12 dx6490dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 39 sec
Reputation Power: 0
Please help the newbie.

I am very new to UNIX, but just playing around with cygwin, I can see that it will work nicely for a project I'm working on. Starting from any given directory, I want my app to spider and collect every filename, size, full path, created date, modified date and last accessed date and save this data in a text file. Yes, this is a server snapshot app to see if changes are made to a production server or if a QA server matches a test server, etc...

I wrote this in VB and although it worked great, it is very slow and if there are more than 100,000 files (which there frequently is) the program will crash or hang.

Can anyone get me started on how write a batch that I can kick off every night and it will do the process noted above and save it to any delimted type file?

I think I can write the batch code if I knew what commands would do what I need here.

Thank you,
Joe

Reply With Quote
  #2  
Old December 28th, 2005, 11:20 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1008
you can try

ls -l to get detailed views for each file in a directory.

you can use ls -Rl to recurse through subdirectories and list in full detail. That won't give full paths though.

You could try writing a script using ls -d though, which lists directories, and loop through each directory listed recursively.

And then you can pipe it all into a file.

eg

command >> filename

appends the output of `command` running into `filename`.

Reply With Quote
  #3  
Old December 28th, 2005, 12:14 PM
stdunbar stdunbar is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 1,728 stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 22 h 41 m 16 sec
Reputation Power: 354
Send a message via ICQ to stdunbar Send a message via Yahoo to stdunbar
dx6490dude - you can't quite get everything you need. Unix file systems by default do not keep a separate time for the creation time and the last modified time. There are three times that are associated with a Unix file or directory:
  • atime - the time of the last access (read). Remember that for read-only file systems (think CD-ROM) this time can not and will not change. And not every system call updates this time.
  • mtime - the time of the last modification.
  • ctime - the time of the last status change. For example, if someone did a chmod on the file.

A "ls -l" will only give you, by default, the last modified time or mtime. It will not give you the last accessed time nor the time of the last status change. There are options to get those values when passed to "ls" but unfortunately you can't get all of them at the same time - you'd have to do multiple passes with "ls" to be able to get them all.

To implement what you want your easiest (well, in my book) way to do this is to look at writing a small C program to recursively traverse a directory tree and call fstat() on every file you find.

However, there are other designs that you might want to consider. The "find" command can show you files that have had any of the three times changed since a start that you specify. For example, you can run a command like:

Code:
find . -type f -amin -10


to find files that have been accessed in the last 10 minutes. Replace -amin with -mmin to find ones that have been modified within the last 10 minutes. Since there are 1440 minutes in a day you could use this to find out both modified and/or accessed files within the last day.

That won't tell you though if any files have changed size. If you are paranoid about security then a file that changed size but didn't have any of the three times changed is likely a bad thing. In that case you might have to "go native" and write a C program to find all of this information at once.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Last edited by stdunbar : December 28th, 2005 at 12:17 PM. Reason: Fixed typo

Reply With Quote
  #4  
Old December 28th, 2005, 01:05 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,587 Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 21 h 21 m 5 sec
Reputation Power: 997
If you can use perl, you might as well write a quick perl script to do this job for you.

Seriously though, what you're saying about checking versions between production and test servers makes me think that you really need to investigate version control programs. There are free ones such as CVS and Subversion and commercial ones such as Perforce that do exactly what you want. Not only that, they allow you to push out the version of the files you want quickly and easily.
Comments on this post
stdunbar agrees!
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month
Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements

Reply With Quote
  #5  
Old December 29th, 2005, 09:50 AM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
I wrote this in VB and although it worked great, it is very slow and if there are more than 100,000 files (which there frequently is) the program will crash or hang.

the 1. probl you have is... you let people crete xthousend files
the 2. probl you have is... you let people crete xthousend files
the 3. probl you have is... you let people crete xthousend files
....
the N. probl you have is... you let people crete xthousend files
...
...
at least, as sys admd, you should know what they are able
to do.



the second is

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Please help the newbie.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT