Please help me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help me
# 1  
Old 11-04-2015
Please help me

write a shell script for delete 1 week old log file????
# 2  
Old 11-05-2015
What shell are you using?
What operating system are you using?
What have you tried?
Where is the log file that you want to remove located?
What is the name of the log file you want to remove?
# 3  
Old 11-05-2015
1)bash shell i am using
2)redhat linux 7 i am using
4)log file are located in /bin/temp/user1/.....
5)and log file name is "error"
# 4  
Old 11-05-2015
I see that you didn't answer the question: "What have you tried?"

You could try the command:
Code:
find /bin/temp/user1 -name 'error' -mtime 7 -exec echo rm {} +

to remove all of the files named error in the file hierarchy rooted in /bin/temp/user1 (which is a VERY strange directory to contain any files since /bin should only contain utilities to run; not data for commands, output from commands, nor logs of executions of commands) that were last modified exactly one week prior to some time during the execution of this find command.

I assume this won't meet your requirements (which are vague), but you can read the man page for find to see how to modify this is you want to remove files more than a week old, files less than a week old, with a timestamp based on the last access time instead of the last modification time, or with a timestamp based on the last time the file status changed instead of the last modification time.
# 5  
Old 11-05-2015
The standard tool that deals with logfiles is logrotate.
Code:
man logrotate

Maybe there is already a file in /etc/logrotate.d/ for your logfile? Then alter it; otherwise create one.
With a suitable logrotate file you don't need an extra find-delete script.
Before you activate a remove/rename/compress on your logfile, check with fuser if it's opened by a process; if yes you need special handling for the process.
# 6  
Old 11-06-2015
thanks to all !!!!
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question