Log archive


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log archive
# 1  
Old 12-23-2014
Log archive

Hi,

I am trying to move old file to archive folder.

find /sourcedirectory/logs/* -type f -mtime +30 -exec mv "{}" /sourcedirectory/logs/archive \;


The above command not only search for old file in /sourcedirectory/logs/ folder but also searchs in /sourcedirectory/logs/archive ( what I meant to say is its doing recursive search.)

I dont want do recursive search. Can you help me in command which does not do recursively.

find /sourcedirectory/logs/* -type f -mtime +30 - which does recursively.

what is the command for non recursive?
Thanks for your help.
# 2  
Old 12-23-2014
Try:

Code:
find /sourcedirectory/logs/* \( -type d ! -name . -prune \) -o \( -type f -mtime +30 -exec mv "{}" /sourcedirectory/logs/archive \; \)

# 3  
Old 12-23-2014
Can you explain above command?

Thanks for your help.
# 4  
Old 12-23-2014
Easier to understand if you break it down, then use man find to understand the different options/flags.

Find all files in the below directory:
Code:
find /sourcedirectory/logs/*

Exclude ("pruning") all directories except (!) the current directory (.):
Code:
find /sourcedirectory/logs/* \( -type d ! -name . -prune \)

where files were modified 30 days ago:[CODE]find /sourcedirectory/logs/* \( -type d ! -name . -prune \) -o \( -type f -mtime +30[/ICODE]then moves the found files to the below directory:
Code:
find /sourcedirectory/logs/* \( -type d ! -name . -prune \) -o \( -type f  -mtime +30 -exec mv "{}" /sourcedirectory/logs/archive \; \)


Last edited by rbatte1; 12-29-2014 at 08:37 AM.. Reason: Changed CODE tags to ICODE tags to make the first paragraph more readable then build up command in stages.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to archive logs and sftp to another archive server

Requirement: Under fuse application we have placeholders called containers; Every container has their logs under: <container1>/data/log/fuse.log <container1>/data/log/fuse.log.1 <container1>/data/log/fuse.log.XX <container2>/data/log/fuse.log... (6 Replies)
Discussion started by: Arjun Goswami
6 Replies

2. Homework & Coursework Questions

Archive and purge the log file

Hi Unix Experts, I am new in this filed. I have assignment to Archive and purge the log file using shell scripts I tried I could not get the result please help me this. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log)... (1 Reply)
Discussion started by: johney1981
1 Replies

3. Shell Programming and Scripting

Create archive and nil the content of log file using script

Plese help I need a urgent requirement. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log) file to 0 kb and then in the archive folder log files are name to test.tar test1.tar test2.tar EX: /home/abc/ test.log ... (1 Reply)
Discussion started by: johney1981
1 Replies

4. Shell Programming and Scripting

Bash Script to decrypt encrypt log and archive

Hi Please see if you have come across any aprts of this. I can read, integrate and syntehsixe. Any help you could offer me would be super. thanks in advance! Good day. Thank you for your response in this matter. Here are some further details: 1) scripting is to be in BASH... (1 Reply)
Discussion started by: cdc01
1 Replies

5. Shell Programming and Scripting

Log archive script

I need a log archival script which will delete files older than 3 days in a given JBOSS log directory which has files as follows server.log.2011-08-25 server.log.2011-08-26 server.log.2011-08-27 server.log.2011-08-28 server.log I only want to save server.log and 3 days before server.log... (1 Reply)
Discussion started by: gubbu
1 Replies

6. Shell Programming and Scripting

moving log file into Archive directory

Hi All, I'm trying to write a script which will do following : - For any old log under trace directory, if found move it to Archive - Check for a process “process-A” if it is running abort from the script - Else start it up (start_process-A.sh this case) - If it fails to start the... (1 Reply)
Discussion started by: mohullah
1 Replies

7. Shell Programming and Scripting

shell script for primary and standby DB archive log check

Hi All, OS:AIX 5.3 64 bits I would like the below script to send alert mail with the message - "Standby logs falling behind Primary" to xyz@yahoo.com Script ===== #!/usr/bin/ksh #----------------------------------------------------------------------------- # Use SQL*Plus to query... (1 Reply)
Discussion started by: a1_win
1 Replies

8. UNIX Desktop Questions & Answers

Aggregate title to an archive.log

Hello how are you, i have a question i have a file ale.log and i want to agregate a title and later a space when the text is over and put another title (when the text is over) how can i do this? thank you Example Last ------>(Title) i want to agregate pupu pupu pupu pupu... (1 Reply)
Discussion started by: enkei17
1 Replies

9. Shell Programming and Scripting

Script to archive log files:Urgent Help required

I have no prior knowledge of Unix shell scripting,but my requriment demands to wrie a script that do fallowing things. 1.Delete older than one year log files 2.Moves files in to the directories as YYYYMM wise. 3.If files in $LOGDIR older than n=2 months tar and move them to $ARCHIVEDIR... (5 Replies)
Discussion started by: vamsx
5 Replies

10. Shell Programming and Scripting

script to archive all the log files

is there a way to write a script and run with a cron job which archives all the *.log files into .tar.gz. :eek: (0 Replies)
Discussion started by: tintedwindow
0 Replies
Login or Register to Ask a Question