Create log file periodically ex: hourly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create log file periodically ex: hourly
# 1  
Old 11-02-2011
Create log file periodically ex: hourly

Hello,

I have a command which runs continuously and creates output to STDOUT. Now, in unix, if I create logging for this command, it would create a single log file and keep on updating. As there is so much data filled in it, I would want to break the log files periodically. In this instance, say if I want to break the log files every hour, how can I do that?

Thanks in advance!
# 2  
Old 11-02-2011
you can rename the logfile every hour by adding time stamp to the name of file . as per your requirement define the $time variable using date command. cron can be used to schedule it every hr.

ex - mv system.log system.log.$time
# 3  
Old 11-03-2011
thanks for the information!

I was able to proceed as you mentioned.
# 4  
Old 11-09-2011
hello,

i was able to do it but then i do not want to run the process/restart the process every hour.

if i start the process now, let it run for the whole day and I would like to create hourly logs without restarting.

is there a way?
# 5  
Old 11-09-2011
Try this...
Code:
#!/bin/bash
#logger.sh script

log_file=/tmp/process.log
tmp_log_file=/tmp/process.log.$$

while true
do
        sleep 3600
        cp $log_file $tmp_log_file
        >$log_file
        mv $tmp_log_file $log_file.$(date +%d%m%Y_%H%M)
done

If interested, you can cron this script to be executed every one hour...

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining files(every 15 min) as one file(hourly)

Hello, My system is generating two files every 15 minutes and file names are given automatically as below. (98,99,89,90 are the sequence numbers) File1_09242013131016_000000098 File1_09242013131516_000000099 File2_09242013124212_000000089 File2_09242013124712_000000090 I want to combine... (6 Replies)
Discussion started by: phoenex11
6 Replies

2. Shell Programming and Scripting

[Solved] Getting the CPU utilization in a file periodically

Hi, I am trying to create a script that will run for every 5 mins to grep the CPU utilization. I have 6 instances running on a single unix server for which I have to export the individual utilizations periodically. Can we fetch the utilization of 6 instances in separate files using top... (8 Replies)
Discussion started by: jhilmil
8 Replies

3. Shell Programming and Scripting

How to create a log file that simply shows the name of a file and what directory it was moved to.

Newbie...Thank you for your help. I am creating my first script that simply generates subdirectories to organize video, music, and text files within those subdirectories from my current working directory. PROBLEM: I am trying to write a log file that contains, for each file, the original file... (0 Replies)
Discussion started by: BartleDoo
0 Replies

4. Solaris

UFS File System Periodically Corrupted - What to check?

The system is a SunFire V440 running SunOS 5.10 About once every 3-4 weeks, the system will reboot into single user mode on its own, and then I run svcs -xv, the filesystem service and dependent services will be disabled due to the metadisk file system being corrupted. The I've been doing... (2 Replies)
Discussion started by: the.gooch
2 Replies

5. Shell Programming and Scripting

FTP a file on Hourly basis

Hi, I have to upload a file test_201105281100.txt to a ftp location. The files will be created on hourly basis like test_201105281100.txt, test_201105281200.txt & so on. After a file is uploaded successfully, I need to rename the file as test_201105281100.success & if it is not uploaded... (11 Replies)
Discussion started by: SunilB2011
11 Replies

6. Shell Programming and Scripting

Increment #'s in text file hourly

I have a text file with a number "001". I am trying to change this number every hour and increment by "1". So every hour it would add +1 to that number. I am able to change the file with sed but unable to have it increment it by "1" without me adding that to the sed command. Any help is... (23 Replies)
Discussion started by: noob33
23 Replies

7. Red Hat

hourly kannel log rotation

I need to Change threshold of rotation of kannel logs. At the moment, Kannel (the SMS gateway system) logs activities in log files which are rotated daily. Due to high traffic, the logs grow fast every day before they are rotated; meaning that the write speeds while logging slow down due to large... (2 Replies)
Discussion started by: Targ
2 Replies

8. UNIX for Dummies Questions & Answers

count string occurance in a file hourly

Hi, I file that has all the status for one day (24hours). Now what I want to do is to count the occurence of a string in its output hourly like for example count occurance of successful or asynchronous clear destinon for every hour and redirect it to file. Please see sample file below. Please... (2 Replies)
Discussion started by: ayhanne
2 Replies

9. UNIX for Dummies Questions & Answers

How do you automate an hourly file check?

Hi, New to the forum, Great site, I can learn a lot from here!! :cool: I would like to know how to automate a command that checks the Sybase database's are "alive" on an hourly basis, and mails outlook if they are not (1 Reply)
Discussion started by: mals
1 Replies
Login or Register to Ask a Question