on 05-30-2013 7:45 AM
Hi,
This is Deepesh I am trying find some script to delete log files in \var\log\applog\nmon . We usually get this alerts that the file system is almost full and all we do is go to the path and delete old log files. So basically what i am looking for is the script that i can schedule in corn job . This script should keep logs for two months and delete the rest .
Hello Deepesh,
You can create a simple unix script using 'find' command. Update the directory name where you want to delete the files. I would suggest to test it before u implement it across the systems
Unix Script:
#!/bin/bash
find <directory> -mtime +60 -type f -exec rm {} \;
Regards,
Mudasir.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I believe those are nmon files with extension .nmon
In that case you can create a script like this:
find . -xdev -type f -mtime +60 -name "*.nmon" -exec rm {} \;
To be sure that it is deleting the correct files list the files first using this:
find . -xdev -type f -mtime +60 -name "*.nmon" -exec ls -ltr {} \;
Regards
RB
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I finally did this
#!/bin/sh
###
### Static variables
###
nmon_dir="/var/log/applog/nmon "
cd $nmon_dir
find $nmon_dir -xdev -type f -mtime +120 -name "*.nmon*" -exec rm {} \;
find $nmon_dir -xdev -type f -mtime +5 -name "*.nmon" -exec gzip {} \;
But I am not sure whether that .gz file will be stored .
Hello
cd $nmon_dir
There is no need to specify cd $nmon_dir in the script as the find command is using the path $nmon_dir which is already defined as a shell varibale.
But I am not sure whether that .gz file will be stored
The files will be zipped in the location where they are present unless you specify another location.
Good Luck
RB
Hi,
Firstly which logs are you referring to?
ABAP/JAVA/ AUDIT logs?
Be careful what you delete bu something similar to Mudasir's suggestion can work.
If your reasoning is for space you can use similar command and add
find <directory> -mtime +60 -type f -exec gzip -9{} \;
So insteaf of removing it zips them
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.