Deleting 3 days old logs from a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting 3 days old logs from a directory
# 1  
Old 12-19-2015
Wrench Deleting 3 days old logs from a directory

As i am working in unix environment so i have an logs that is created by my application at the following location that is

PHP Code:
 /opt/app/glac/current/servers/ops/logs 

inside the logs directory there are different kinds of logs(that is the file having extension as .log ) have been created ,can you please advise i want to write a shell script such that that script will ask the user the number of day such that if user enter the value 3 so in that case it will delete all the logs that are 3 days old , lets say if date is 19 dec 2015 and if user enter the value as 3 then it will delete the logs including of 16 dec also it will only keep the logs of 17,18 and 19 dec only

please advise what will be the shell script to achieve this Smilie
# 2  
Old 12-19-2015
Any attempts/ideas/thoughts from your side? Did you consider the links into these fora given at the bottom of this page?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Scripting for deleting logs

Hi, i wants to create the script for my linux server. my system log files are getting huge frequently /root file system getting filled frequently.so wants to delete the logs when it crossed 1GB data on it. Please help me how do i create the bash script.. i use solaris 10 OS... (3 Replies)
Discussion started by: Rahulne25
3 Replies

2. Shell Programming and Scripting

Delete logs older than 60 days

i am using HP-UX OS...... delete logs older than 60 days find -mtime +60 | grep -i '.*log' | xargs rm -mtime is nt available in HP-UX, pls tell me other option ? (2 Replies)
Discussion started by: only4satish
2 Replies

3. Shell Programming and Scripting

[Solved] Fetching logs of last few days from logfile

Hi All, I have a requirement to fetch logs of last 'N' days. I am trying the following command which is working fine if it finds the date of that day in logfile. START=`TZ="GMT+$((24*N))" date +"%Y %b %d"` this is being used to fetch 'N'th day's date and awk '/'"$START"'/{p=1}... (24 Replies)
Discussion started by: KDMishra
24 Replies

4. Shell Programming and Scripting

To delete logs older than 30 days

I want to write a shell script that deletes all log files in a directory that are older than 30 days except for 3 files: I am using the following command: find /tmp/logs -name "*.log" -mtime +30 -exec rm -f {} \;But this command deletes all the log files. How can i modify this script that... (5 Replies)
Discussion started by: mmunir
5 Replies

5. Shell Programming and Scripting

How to remove the logs more than 5 days old

All, How to remove the logs that are more than 5 days old from a particular folder. Help will be highly appreciated. Regards Oracle User (2 Replies)
Discussion started by: Oracle_User
2 Replies

6. UNIX for Dummies Questions & Answers

Delete last 10 days logs

Hi Can u please tell me how to delete last 10 days logs .. (9 Replies)
Discussion started by: pb18798
9 Replies

7. UNIX for Advanced & Expert Users

how to archive logs older than 5 days & then delete them?

My code is tar -cvf logs.tar `find /usr/openv/logs/512*.log -mtime +2` && find *.log* -mtime +2 -exec rm {} \; this gives me output as: tar: Missing filenames:confused: (1 Reply)
Discussion started by: timus1980
1 Replies

8. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies

9. UNIX for Dummies Questions & Answers

Deleting certain files over 30 days old

Hi, I must confess i have a very basic knowledge of UNIX and its commands, but i was hoping someone would be able to help answer my query. Once a month as part of a team we have to perform housekeeping on our UNIX directories, we remove certain files older than 30 days and compress the... (3 Replies)
Discussion started by: swellybro
3 Replies

10. Shell Programming and Scripting

Deleting files over 7 days old

Simple question I am sure - but one that I dont know the answer to nevertheless.. I have a directory that I store log files in - but I wish to run a daily script in cron to delete all files in this directory that have not been modified within the last 7 days... Can anyone help me? (10 Replies)
Discussion started by: frustrated1
10 Replies
Login or Register to Ask a Question