Shell script to copy a log file if it exceeds 5000000 bytes
Hi,
on unix box, under /local/home/userid/logs folder, apps generated the following files
sw_warn.log
sw_error.log
eaijava.log
if there any application specific errors, the above file will keep growing.
if the file exceed 5000000 bytes, I would like to have a shell script which do the following
1) copy logs files from /local/home/userid/logs into /local/home/userid/logs/yyyy_mm_dd_timestamp.
2) Shell script should create a folder yyyy_mm_dd_timestamp.
3) Also, delete the files from /local/home/userid/logs
4) if deleting files are not recommended then delete the contents.
so far i have come up with the following
-------------------------------------------
We don't know your system.
Are the files open by an application at the time of the log file maintenance slot?
[me] yes these files are open by the apps
(If so, don't delete them, null them!).
[me] how?
Please show sample directory lists of every directory listed.
[me] the directory path is /local/home/userid/logs. under logs directory, i have three files
sw_warn.log
sw_error.log
eaijava.log
What is the maximum growth rate of the files? This determines how often to check.
[me] - i don't know the growth rate. btw, how to scheudle the shell script which keep checking the file size and run the script
Are there any disc space issues?
[me] no disc space issue.
Last edited by Franklin52; 01-04-2011 at 04:23 AM..
Reason: Please use code tags
e.g. To null an open file called "logfile" (after copying it of course) using a Shell which is running as a user with sufficient permissions.
On the subject of scheduling, use unix "cron" to schedule routine maintenance tasks. The maintenance frequency depends on the growth rate and local rules.
Most Systems Administrators schedule logfile maintenance weekly on a Sunday night.
Personally I schedule such jobs for 12:00 (lunchtime) daily which gives you a chance to read the overnight logs before your second coffee.
Imho, keeping log files down to a readable size (albeit backed with many days of history) can save you when you need information about a hot problem in a hurry.
Hmm. By this time tomorrow you will know the growth rate ... won't you?
Quote:
TODAY=`date +%d/%m/%y`
CURTIME=`date +%H:%M:%S`
It is not advisible to use characters such as colons and solidi in filenames. It can (and does) confuse multi-platform backup software as well as making subsequent processing in Shell painful. Unix will not stop you creating such filenames because they are valid. The solidus will give you the most grief becuse it is the directory delimiter in the full hierarcial pathname to a file.
This line does not work - there are no variable names preceded with a dollar sign and the "mkdir" command never runs.
Quote:
today_dir=mkdir TODAY_CURTIME
I'll leave that one for you to work out.
Last edited by methyl; 01-03-2011 at 06:40 PM..
Reason: spellin
My proposed solution:
To be honest, if you are running the script once a day or week, then:
or even:
would be more than sufficient.
But I have to admit the statement:
Quote:
Originally Posted by lookinginfo
Are there any disc space issues?
[me] no disc space issue.
bothers me. There are always disk space issues -- disks may be cheap, but no one has infinite disk space. IMHO, rotating the logfiles is "better", for it limits the total size of the logs to the number of rotations times 5M (plus or minus). Change the body of the while loop to:
Run this version of the script once a week, and you will retain a minimum of ten weeks of logs.
hello,
suppose, entered input is of 1-40 bytes, i need it to be converted to 40 bytes exactly.
example: if i have entered my name anywhere between 1-40 i want it to be stored with 40 bytes exactly.
enter your name:
donald duck (this is of 11 bytes)
expected is as below - display 11... (3 Replies)
How can i remove a file using shell script when its size exceeds 10MB. Given that file is located in different location to the shell script where it is running? (4 Replies)
I have a text file which got 6th coloumn as date and 7th coloumn as time. The text contains data for last one week. I need to remove all the data whose date & time is after 03/08/2011 06:00:00 and save it on another file
TEXT FILE
========
6 dbclstr-b IXT_Web Memphis_Prod_SQL_Diff... (4 Replies)
Dear all,
I have a database with thousands of files with the structure of name is:
Filename_hour_year.abc
Filename_hour_year_1.abc
..............
So what I need is how to write a script that all file with contain the character "_1" will copy to "_2"
For example: file name:... (7 Replies)
Hi,
I want to copy some files from a Folder say, /usr/X at random intervals to another location.
Basically, new files will be dumped at random intervals to location /usr/X and I have to copy those new files to some other location (after copying, I cannot delete those files from source... (2 Replies)
Hi everyone,
the problem is quite simple, yet I can't find an easy solution using awk.
I need to search for a string in $3, then if I find this string, copy the line,modify $3, and copy the next 9 lines to the same file.
My problem is in the copying of the lines... Finding and modifying... (5 Replies)
Hi All,
OS:AIX 64 bits.
Requirement is to convert file_size from bytes to megabytes through shell script as below:
export DBALIST="xyz@rediffmail.com"
ls -ltr abcd.txt > file_size.result
export file_size=`awk -F" " '{ print $5 }' file_size.result`
if ]
then
mailx -s "File abcd.txt... (3 Replies)
Compete noob question....
I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory
help please :eek: (9 Replies)
Hi all,
Does anybody know or guide me on how to remove the first N bytes and the last N bytes from a binary file? Is there any AWK or SED or any command that I can use to achieve this?
Your help is greatly appreciated!!
Best Regards,
Naveen. (1 Reply)
I'm looking to create a Korn Shell script that, if given a directory as an arg, will calc bytes used by all files in the given directory and display that info. If no command line arg is given the program is to calc and display the bytes used by all the files in the pwd.
Example output:
... (3 Replies)