Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm afraid it's not possible since the files have been actually created at the same time or at least below the time resolution of the filesystem. For example consider the following:
there is no difference in nanoseconds among the timestamps because this information is not stored in the filesystem (ext3 in my example). I'm not sure about this, but the resolution of the ext4 filesystem should lower to 1 nanosecond.
Note also that there is no 'file creation' time in Unix: it's atime (file access), mtime (file content modified), ctime (inode info Change time ie change of content in owning dir file eg owner, perms etc).
Let me entered into one more level for explaining my requirement.
One process is putting files(file.start and file.end) in common directory. That process will create file.start at first then only file.end.
As of now using "ls -1(one)rt" command getting the files which the way the process created. Process the file.start file and followed by file.end
I should not process file.end at first ( Expected one)
Sometime it may create the files(file.start and file.end) at the same time. ( This can't be controlled )
At that time I need to parse the file.start file first and file.end file next.
So give me some mechanism (programming ,commands..etc) to achieve this in Unix?
NOTE: Doing the development in C programming language.
Loosely speaking , there are (at least) 3 ways to process files in order
1. by timestamp, if a diff in timestamp exists
2. by filename if the filenaming convention allows eg names are created to a pattern that evolves predictably. Typically this would mean the date/time is part of the filename, but any serial num etc in the name would suffice (eg your example filenames is an easy one)
Obviously there must be some differences in the filenames or it'd be overwriting the one file.
3. by file content; again if the content allows it
Expected one :
First need to parse .start extension file and wait for .end file this is one cycle. Here the problem is that if the files are created at the same time then going to parse .end extension file at first. because of relying on the ls -lrt command.It shouldn't be.
NOTE: Don't want to change the things in the process who put the files in the directory. Give me suggestion to the place where the files are being obtained.
Also note that it should be LIVE . It should not take more time to get the .end extension file for the relevance file.
If I understand the requirement well, why not listing only the .start files, then looking for the matching .end? E.g. something like:
Code:
startfile=$(ls -t *.start | head -n1)
# parse file .start here
# now wait for matching file .end to appear
endfile=${startfile/.start/}.end
while [[ ! -f $endfile ]]
do
sleep 5
done
# parse file .end now
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.