Visit Our UNIX and Linux User Community


handle file by month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting handle file by month
# 1  
Old 09-23-2009
handle file by month

Hi,

I want to write a shell script which handle an oracle alert log so that when it changes month, the script generates a new file with month in the filename.

Thanks in advance.

Leim
# 2  
Old 09-23-2009
Quote:
Originally Posted by leim
...
so that when it changes month,
...
What do you mean by "when it changes month" ?

Do you just want to create a new file, say, "alert_Mon.log" on the 1st of every month, where Mon is the 3-character month abbreviation ?

Code:
if [ "$(date +%d)" == "01" ] ; then  touch alert_$(date +%b).log; fi

tyler_durden
# 3  
Old 09-23-2009
Thanks for reply.

The scenario is like:
1. A cron job run alert_mgt.sh every 5 mins
2. If there is no error in the alert.log, it merges the alert.log to this month alert log say, alert.log.Sept2009.
3. If there is error in the alert.log, it grep it and mail it out to dba, then it merges the alert.log to alert.log.Sept2009. (At the same time, it can write some note in the place where the error ocurred in the alert.log.Sept2009)
4. When month changes (10/01/2009 00:00:00), it generate a new log alert.log.Oct2009.

Thanks in advance.
leim
# 4  
Old 09-23-2009
You can look at logrotate if your distribution supports.

logrotate(8) - Linux man page
# 5  
Old 09-24-2009
Java The script

ok Here is the script... You need to adjust according to you system some paths etc ...
Most of it will work once you make necessary changes.

------------------------------------------------------------------------------

ERRMESG="[ $(/bin/date) ]Something went wrong with Monitoring script.."
if grep -i Error /pathto/log/alert.log
then
ERRMESG="[ $(/bin/date) ] Errors in the logs $(grep -i Error /pathto/log/alert.log)"
echo $ERRMESG | mail -s 'Error in /pathto/log/alert.log' dba@whatever
else
ERRMESG="[ $(/bin/date) ]: The log file has been truncated."
fi
cat /pathto/log/alert.log >> "/pathto/log/alert.log.$(/bin/date +%b%Y)"
echo $ERRMESG >> "/pathto/log/alert.log.$(/bin/date +%b%Y)"

------------------------------------------------------------------------------

Do reply back with changes and working script ...

Previous Thread | Next Thread
Test Your Knowledge in Computers #853
Difficulty: Medium
AngularJS most notable feature is the two-way data binding.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

2. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

3. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

4. UNIX for Advanced & Expert Users

How to decode nfs file handle in HP-UX?

Hi Experts, Any idea how to decode file handle in HP-UX? I am getting the following error continously in my HP-UX 11.31 box :mad: Apr 26 07:15:00 host62 su: + tty?? root-bb Apr 26 07:15:00 host62 su: + tty?? root-abcadm Apr 26 07:15:01 host62 vmunix: NFS write error on host peq9vs:... (1 Reply)
Discussion started by: vipinable
1 Replies

5. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

6. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

7. AIX

how to handle potential file contention

I need to change how a posting procedure currently works in order to improve load balancing but I am hitting a potential file contention problem that I was wondering if someone here could assist me with... In a directory called FilePool I would have a bunch of files that are constantly coming in... (3 Replies)
Discussion started by: philplasma
3 Replies

8. Programming

deleting a file name by its handle

All, I am having three function 1.open 2.process 3.close. Open will open a file and process will process a file and close will close the file .. I can able to close the file by its filehandler.Is there is anyway that i can get the file name by filehandle and remove it after... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

9. UNIX for Advanced & Expert Users

Stale NFS file handle

Hi, I get an error saying "Stale NFS file handle" how can I solve this? Is it possible to do this with a umount/ mount command? (5 Replies)
Discussion started by: rein
5 Replies

10. UNIX for Advanced & Expert Users

NFS file handle

How can I kill mount connection(NFS , made by automount) if remote filesystem is down? I tried: fuser -ku /auto /auto: umount /auto nfs umount: ERROR: /auto is busy If I try cd /auto - I get - /auto: Stale remote file handle. I know that reboot will help but I cannot reboot this... (2 Replies)
Discussion started by: kazimir
2 Replies

Featured Tech Videos