Move all .log except those generated in the last 5 minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move all .log except those generated in the last 5 minutes
# 1  
Old 05-07-2013
Move all .log except those generated in the last 5 minutes

RHEL 5.8
In the directory /u03/pkms/app_logs I have several hundreds of log files as shown below.
Code:
$ pwd
/u03/pkms/app_logs

$ ls -alrt *.log | tail -50
-rw-r----- 1 oracle dba  9439232 May  4 13:57 mvtpcem_1_722892404_94157.log
-rw-r----- 1 oracle dba  9227264 May  4 13:57 mvtpcem_1_722892404_94158.log
-rw-r----- 1 oracle dba  9216000 May  4 13:57 mvtpcem_1_722892404_94159.log
-rw-r----- 1 oracle dba  9056256 May  4 13:57 mvtpcem_1_722892404_94160.log
-rw-r----- 1 oracle dba 10231296 May  4 13:57 mvtpcem_1_722892404_94161.log
-rw-r----- 1 oracle dba  9932800 May  4 13:57 mvtpcem_1_722892404_94162.log
-rw-r----- 1 oracle dba 10440192 May  4 13:57 mvtpcem_1_722892404_94163.log
-rw-r----- 1 oracle dba 10412032 May  4 13:57 mvtpcem_1_722892404_94164.log
-rw-r----- 1 oracle dba  9217024 May  4 13:57 mvtpcem_1_722892404_94165.log
-rw-r----- 1 oracle dba 10384384 May  4 13:57 mvtpcem_1_722892404_94166.log
-rw-r----- 1 oracle dba  9237504 May  4 13:57 mvtpcem_1_722892404_94167.log
-rw-r----- 1 oracle dba  9022464 May  4 13:57 mvtpcem_1_722892404_94168.log
-rw-r----- 1 oracle dba  9708032 May  4 13:57 mvtpcem_1_722892404_94169.log
-rw-r----- 1 oracle dba  9963008 May  4 13:57 mvtpcem_1_722892404_94170.log
-rw-r----- 1 oracle dba 10061312 May  4 13:58 mvtpcem_1_722892404_94171.log
-rw-r----- 1 oracle dba 10278400 May  4 13:58 mvtpcem_1_722892404_94172.log
.
.
.
<snipped for readability>
.

-rw-r----- 1 oracle dba   304128 May  4 14:13 mvtpcem_1_722892404_94199.log
-rw-r----- 1 oracle dba  1370112 May  4 14:21 mvtpcem_1_722892404_94200.log
-rw-r----- 1 oracle dba   337920 May  4 14:25 mvtpcem_1_722892404_94201.log
-rw-r----- 1 oracle dba    18944 May  4 14:26 mvtpcem_1_722892404_94202.log
-rw-r----- 1 oracle dba     5632 May  4 14:26 mvtpcem_1_722892404_94203.log
-rw-r----- 1 oracle dba     1024 May  4 14:26 mvtpcem_1_722892404_94204.log
-rw-r----- 1 oracle dba     1024 May  4 14:26 mvtpcem_1_722892404_94205.log
-rw-r----- 1 oracle dba     1024 May  4 14:26 mvtpcem_1_722892404_94206.log

I want to move all .log files to another location /u05/nmbs/may13, but skip those .log files which was
generated within the last 5 minutes. How can I do this ?
# 2  
Old 05-07-2013
Hii

Below command will help you in this task.

Code:
find /u03/pkms/app_logs/*.log -mmin +5 | xargs -I '{}' mv {} /u05/nmbs/may13/ 

This User Gave Thanks to Sod For This Post:
# 3  
Old 05-07-2013
Thank you Sod.
Do you prefer xargs over -exec ?
What is -I option in xargs ? Couldn't find the details about xargs in find's man page.
# 4  
Old 05-07-2013
Because it's in the xargs man page Smilie
This User Gave Thanks to Scott For This Post:
# 5  
Old 05-07-2013
Oh Ok. I just noticed the pipe symbol. Thank you Scott, Sod

Do you prefer xargs over -exec for doing things within find command?

Is there a term for 'doing things within' another in command in shell scripting terminology ?
# 6  
Old 05-07-2013
Generally, I strongly prefer find -exec over xargs. It can process any valid filename with less overhead (-exec ... {} +) than xargs.

People often treat xargs as if it can handle any type of filename, but that is not the case. Depending on the options in effect, quotes, whitespace, and a logical EOF character can be mishandled. To be fair, in practice, these limitations are seldom relevant when dealing with local, UNIX files. However, when handling files from other filesystems, whitespace isn't uncommon. When dealing with p2p files, even quotes aren't unheard of.

Piping to xargs also adds overhead:
(1) Data needs to be copied back and forth between kernel and userspace twice as often.
(2) If find and xargs must run on the same CPU, more context switches are required.

Unless some xargs functionality is required, I would not use it.

Regards,
Alister

Last edited by alister; 05-07-2013 at 01:55 PM.. Reason: Missing word and elaboration on the possibility of encountering problematic names
# 7  
Old 05-07-2013
I agree with Alister.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

How to capture hostnames or ip address in the log files generated?

Team, I have prepared a script which I run from my remote machine(Jump-box)server Below is the script FILEDATE=`date +%F` LOGFILE=/home/abc/scripts/xyz.$FILEDATE.log find /home/abc/scripts/xyz.*.log -type f -mtime -3 -delete touch $LOGFILE exec 1>$LOGFILE 2>&1 #healthcheck batch runs... (1 Reply)
Discussion started by: whizkidash
1 Replies

4. Shell Programming and Scripting

Log file being not generated in crontab

My shell script it.sh #!/bin/sh ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH today=`date "+%m-%d-%Y %H:%M:%S"`; export today CUR_DIR=$1; export CUR_DIR LOG_FILE=error.log; export LOG_FILE # Direct script output to... (4 Replies)
Discussion started by: rafa_fed2
4 Replies

5. Shell Programming and Scripting

Script to grep for a string in log files generated in last 15 minutes.

Dear Guru's I've a requirment to grep for a string in series of log files that are getting generated almost every minute. I'm looking to schedule a script every 15 mountes,in order to check if the error string has been generated in any of the log files generated in last 15 minutes. Please... (3 Replies)
Discussion started by: rajivatnova
3 Replies

6. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

7. UNIX for Dummies Questions & Answers

Log file not getting generated

Hi , Log file is not getting generated. any suggestion? Thanks date1=$(date '+%m/%d/%y-%H:%M:%S') log="wrapper.log.$date1" echo " somethng" > $log (2 Replies)
Discussion started by: ajincoep
2 Replies

8. Ubuntu

How can I move a file to a webserver every 5 minutes?

I'm using Ubuntu and I have a text file I want to FTP to a web server every 5 minutes. I want to overwrite the existing file every time so I don't have tons of the same file. (10 Replies)
Discussion started by: Bradj47
10 Replies

9. UNIX for Dummies Questions & Answers

Script to move certain number of files every 10 minutes.

Hi, I need to move a certain number of files every 10 minutes from one folder to another. I have written the script below, however its not working, please advise. #! /bin/ksh start() { mv /test1/$(head -1000 /movetst) /test2/ sleep 600 } stop() { exit } ls ti* >... (1 Reply)
Discussion started by: amitsayshii
1 Replies

10. Shell Programming and Scripting

get the last generated log file

Hi I need to get the last generated file in a directory using ls -ltr. I need to store the output of ls -ltr in a variable. it will like this $xyz = -rw-rw-r-- 1 sblp003 siebel 1060 Dec 18 13:33 from this output, I need to do a substring to get this value alone "Dec 18... (8 Replies)
Discussion started by: ragha81
8 Replies
Login or Register to Ask a Question