Unix - one to one correspondence to files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix - one to one correspondence to files
# 1  
Old 08-24-2012
Unix - one to one correspondence to files

Hello,

I am writing a Log Unifier program. That is, I have a system that produces logs:
my.log, my.log.1, my.log.2, my.log.3...

I want on each iteration to store the number of lines I've read from a certain file, so that on the next iteration - I can continue reading on from that place.

The problem is that when the files are full, they roll:
The last log is deleted
...
my.log.2 becomes my.log.3
my.log.1 becomes my.log.2
my.log becomes my.log.1
and a new my.log is created

I can ofcourse keep track of them, using inodes - which are almost a one-to-one correspondence to files.

I say "almost", because I fear of the following scenario:
Between two of my iterations - some files are deleted (let's say the logging is very fast), and are then new files are created and some have inodes of files just deleted. The problem is now - that I will mistake these files as old files - and start reading from line 500 (for example) instead of 0.

So I am hoping to find a way:
1. Either another 1-to-1 correspondence other than inodes.
2. An ability to mark a file. I thought about using chmod +x to mark the file as an existing file, and for new files that don't have these permissions - I will know they are new - but if somebody were to change the permissions manually, that would confuse my program. So if you have any other way to mark.
3. I thought about creating soft links to a file that are deleted when the file is deleted. That would allow me to know which files got deleted.
4. Any way to get the "creation date"
5. Any idea that comes to mind - maybe using timestamps, atime, ctime, mtime in some clever way - all will be good, as long as they will allow me to know which files are new, or any idea creating a one-to-one correspondence to files.

Thank you
# 2  
Old 08-24-2012
If you have a filesystem that supports extended attributes, you could use them to store information, like:
Code:
$ setfattr -n user.key -v value test
$ getfattr -n user.key test
# file: test
user.key="value"

---------- Post updated at 08:44 ---------- Previous update was at 08:42 ----------

BTW: don't forget to prefix the attribute name with "user." or you'll get an setfattr: test: Operation not supported error.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX command to copy files from Windows to UNIX box

Hi Folks, I have a file name abc.xml in my windows machine at the location c:\ytr\abc.xml which I want to place at the unix box machine inside cde directory.. at the following location that is /opt/app/cde/ now the credentials of unix box are abc345 -->(dummyid) ftyiu88--->(dummy passwd) ... (4 Replies)
Discussion started by: punpun66
4 Replies

2. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

3. Homework & Coursework Questions

Unix script Unix script which counts no. of files/sub-files

Hi All, For past some days iam trying, which not able to get to..so please help me on this.. My exact requirement is... Step1: Find how many files/sub files exist in /some/path (maybe in multiple path) Step2: Count the no. of files/sub files with their respective size. Step3: Then a file... (0 Replies)
Discussion started by: sam09
0 Replies

4. UNIX for Dummies Questions & Answers

write a program in c in unix that display the files(includ sub-direc and files within) in a sorted

the sorting is based on name of file, file size modification time stamps o f file it should dislay the output in the following format "." and ".." enteries should be ignored please give some idea how to do it (1 Reply)
Discussion started by: pappu kumar jha
1 Replies

5. Shell Programming and Scripting

How to extract data from indexed files (ISAM files) maintained in an unix server.

Hi, Could someone please assist on a quick way of How to extract data from indexed files (ISAM files) maintained in an UNIX(AIX) server.The file data needs to be extracted in flat text file or CSV or excel format . Usually we have programs in microfocus COBOL to extract data, but would like... (2 Replies)
Discussion started by: devina
2 Replies

6. HP-UX

Copying files from one unix to another unix box

Need a clarification .... While copying files from one unix to another unix box . I am working on two / three unix boxes which are all in a network.. in which home directory are mounted ..(I didn't understand what is the exact meaniing of that) So can i copy the files from one box to another... (2 Replies)
Discussion started by: girija
2 Replies

7. Post Here to Contact Site Administrators and Moderators

Thank you for correspondence

There is no indication (that I can find) as to who sent me the eMail regarding my occasional visits to this forum. I do come and browse at times, and want to keep my name on your list. However, I am not far enough along in my understanding of code to participate except for an occasional "dummies"... (0 Replies)
Discussion started by: Goldenbill
0 Replies

8. HP-UX

to get the timestamp of files from the files and folders in Unix

Hi, I had a directory and many subdirectories and files with in it. Now i want to get the timestamp of files from the files and folders recursively. :( Please help me to generate a script fort he above mentioned requirement! Appreciate for ur qick response Thanks in advance! ... (2 Replies)
Discussion started by: kishan
2 Replies

9. Filesystems, Disks and Memory

Unix Sco Open Server, Windows Computers Problem Access Unix Shared Files Help!!!!!

Hello Moto I hope someone can help We's here at work, have a unix box with sco openserver 5 on it, so it has a nice gui interface.. and also a fair few windows computers.. a system admin guy b4 me, has set up a user called neil, which can, when u try to access the unix box using windows... (2 Replies)
Discussion started by: haggo
2 Replies
Login or Register to Ask a Question