- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Simple C program to process a UNIX file?
Operating System - HP-UX
1752579
Members
3076
Online
108788
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2004 05:41 AM
тАО11-19-2004 05:41 AM
I want to write a C program that constantly loops around and checks the "last modified" date of a given file.
This file is a data file that is randomly ftp'd to me by someone else (always to the same place and with the same name).
I want to process the file if it is "new" ie if I haven't processed it before.
I have no idea how to do this easily.
Anyone have any ideas? many thanks....
Pete
This file is a data file that is randomly ftp'd to me by someone else (always to the same place and with the same name).
I want to process the file if it is "new" ie if I haven't processed it before.
I have no idea how to do this easily.
Anyone have any ideas? many thanks....
Pete
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2004 06:04 AM
тАО11-19-2004 06:04 AM
Solution
The key to what you are trying to do is the stat() system call. Man 2 stat for details but doing this in C is drastic overkill. Perl has the stat function that is based on the underlying system call and will easily handle this task:
I'll attach a Perl Script that will do this quite easily and the rest can be a simple shell script:
#!/usr/bin/sh
TARGET="/xxx/yyy/myfile"
DELAY=300 # seconds
typeset -i LASTMTIME=0
typeset -i STAT=0
while [[ ${STAT} -eq 0 ]]
do
MTIME=$(fileage.pl -m -e ${TARGET})
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
if [[ ${LASTMTIME} -ne ${MTIME} ]]
then
if [[ ${LASTMTIME} -ne 0 ]]
then
# yor actual processing goes here
fi
LASTMTIME=${MTIME}
fi
sleep ${DELAY}
fi
done
exit ${STAT}
Invoke the perl script, fileage.pl w/o arguments for full usage.
I'll attach a Perl Script that will do this quite easily and the rest can be a simple shell script:
#!/usr/bin/sh
TARGET="/xxx/yyy/myfile"
DELAY=300 # seconds
typeset -i LASTMTIME=0
typeset -i STAT=0
while [[ ${STAT} -eq 0 ]]
do
MTIME=$(fileage.pl -m -e ${TARGET})
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
if [[ ${LASTMTIME} -ne ${MTIME} ]]
then
if [[ ${LASTMTIME} -ne 0 ]]
then
# yor actual processing goes here
fi
LASTMTIME=${MTIME}
fi
sleep ${DELAY}
fi
done
exit ${STAT}
Invoke the perl script, fileage.pl w/o arguments for full usage.
If it ain't broke, I can fix that.
- Tags:
- stat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2004 06:29 AM
тАО11-19-2004 06:29 AM
Re: Simple C program to process a UNIX file?
A minimal "C" example.
Needs at least somem errno handling.
Hein.
#include
#include
#include
struct stat buf;
time_t st_ctime_last;
main (int argc, char *argv[])
{
while (!stat(argv[1], &buf)) {
if (buf.st_ctime > st_ctime_last) {
printf ("!\n");
st_ctime_last = buf.st_ctime;
} else {
printf (".\n");
}
sleep (5);
}
}
Needs at least somem errno handling.
Hein.
#include
#include
#include
struct stat buf;
time_t st_ctime_last;
main (int argc, char *argv[])
{
while (!stat(argv[1], &buf)) {
if (buf.st_ctime > st_ctime_last) {
printf ("!\n");
st_ctime_last = buf.st_ctime;
} else {
printf (".\n");
}
sleep (5);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2004 06:44 AM
тАО11-19-2004 06:44 AM
Re: Simple C program to process a UNIX file?
Many thanks to both contributers. This forum never ceases to amaze me.
.. The really good side of human nature
.. The really good side of human nature
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP