files older than 10 minutes


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users files older than 10 minutes
# 1  
Old 10-11-2011
files older than 10 minutes

Hi,
I have to find the files older than 10 minutes and remove those files as well as redirect the file names into a log file.
i am using sun OS and my unix is not GNU and also not having perl.
Could any one suggest me the way to approach. It would be great if script is provided.

Also following commands are not supporting.

Code:
date -v
find . -type f -mmin -10
                   (find: bad option -mmin)

Thanks.

Last edited by radoulov; 10-11-2011 at 12:29 PM..
# 2  
Old 10-11-2011
Quote:
Originally Posted by rohan10k
[...]
i am using sun OS and my unix is not GNU and also not having perl.[...]
Never seen a Sun OS without Perl ...
# 3  
Old 10-11-2011
I don't use SunOS, but perhaps you can accomplish your goal using the following POSIX functionality:

1) Use touch to create a file whose mtime is 10 minutes in the past.
2) Use find's -newer (negated with !) to match files that are older than the file which was touched.

Regards,
Alister
# 4  
Old 10-11-2011
firstly you are using sun os but which one 8-9-10-11 or older ?

1-)if you dont have gnu findutils then you must use (have to) use perl with find the modif minutes.
2-)or might be install gnu-coreutils to use stat command for get file times.
ftp://ftp.sunfreeware.com/pub/freewa...sparc-local.gz
ftp://ftp.sunfreeware.com/pub/freewa...ls-8.11.tar.gz
3-)or you have to use method of @alister , but everytime..
4-)or can write a c/perl program..
Code:
time.h -->
struct timeval {
        time_t          tv_sec;         /* seconds */
        suseconds_t     tv_usec;        /* and microseconds */
};

Code:
stat.h -->
struct stat {
        dev_t           st_dev;
        ino_t           st_ino;
        mode_t          st_mode;
        nlink_t         st_nlink;
        uid_t           st_uid;
        gid_t           st_gid;
        dev_t           st_rdev;
        off_t           st_size;
        timestruc_t     st_atim;
        timestruc_t     st_mtim;
        timestruc_t     st_ctim;
        blksize_t       st_blksize;
        blkcnt_t        st_blocks;
        char            st_fstype[_ST_FSTYPSZ];
};
 
#define st_mtime        st_mtim.tv_sec

Code:
time_impl.h -->
typedef struct timespec timestruc_t;    /* definition per SVr4 */

maybe you can this.
Code:
# cat agenew.c
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char* argv[]) {
int modift;struct stat* buf;
buf=(struct stat *)malloc(sizeof (struct stat));
if (stat(argv[1],buf) != 0) {
perror(argv[1]);
return EXIT_FAILURE;}
(int) modift =difftime(time(NULL),buf->st_mtime);
printf("%d\n",modift);}

Code:
# gcc agenew.c -o agenew ; for file in `find . -type f `; do agemin=$(echo "`./agenew $file`/60"|bc)
if [ $agemin -gt 10 ] ; then echo "$file's age is $agemin min" ; fi; done

regards
ygemici

Last edited by ygemici; 10-12-2011 at 05:48 AM..
# 5  
Old 10-11-2011
Its always a good idea to do a
Code:
man find

and see what options your find allows you to do. The man files are always very helpful in these regards.
# 6  
Old 10-11-2011
Files older than 10 minutes

Hi, I have to find files older than 10 minutes and have to remove those files as well as to redirect file names into log file.

I am using SUNOS unix and it is not having GNU version.
Also below commands are not supporting.
Code:
date -v
find . -type f -mtime +10

could any one help me for this requirement.

Moderator's Comments:
Mod Comment Please use code tags

Last edited by zaxxon; 10-12-2011 at 03:24 AM.. Reason: code tags, see PM
# 7  
Old 10-12-2011
Thanks for the solutions. I would like to go with following solution.
(1) Use touch to create a file whose mtime is 10 minutes in the past.
(2) Use find's -newer (negated with !) to match files that are older than the file which was touched.

Here, how to create a file dynamically whose time is 10 minutes past by comparing with current time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find if create time of last created file in a directory is older than 5 minutes

A process xyz is running and creating file1, file2, file3, .... filen. how do i know if the process has stopped and createtime of the last file (filen) is older than 5 minutes? OS is AIX (3 Replies)
Discussion started by: malaika
3 Replies

2. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

3. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

4. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

5. 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

6. UNIX for Advanced & Expert Users

Help with get/mget from FTP server with files older than 10 minutes

Hi! I am new to unix and this forum as well.. Can someone please help me : I want to "get/mget" files which are older than 10 minutes from a remote FTP server like "ftp.com". After getting the files to local unix server say "Prod.com" , i need to delete only those files from ftp.com which... (4 Replies)
Discussion started by: SravsJaya
4 Replies

7. Shell Programming and Scripting

how to delete the older files other than the recently added 5 files

Number of files will get created in a folder automatically daily.. so i hav to delete the older files other than the recently added 5 files.. Could u help me through this..?? (5 Replies)
Discussion started by: shaal89
5 Replies

8. Shell Programming and Scripting

delete files older than 5 minutes in directory (recursively)

sorry guys can some please give me a hint how to achieve this in a slick oneliner? delete files older than 5 minutes in specified directory (recursively) peace (3 Replies)
Discussion started by: scarfake
3 Replies

9. Shell Programming and Scripting

only find files older than x minutes old

I am looking for a way to show files that have been created within a certain period (say anything older than 10 minutes or so). Is there a command/series of commands I can do this with? As an example, I have the following in a directory: -rw-r--r-- 1 owner group 70175 May 16 09:10... (1 Reply)
Discussion started by: dsimpg1
1 Replies

10. Shell Programming and Scripting

files older than 15 minutes

Hi Friends, i have to write a script to raise a flag if there are any files that are older than 15 minutes in the directory.The directory is supplied as the parameter to the script. please help with a sample script. Thanks in advance veera (0 Replies)
Discussion started by: sveera
0 Replies
Login or Register to Ask a Question