LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 08-15-2011, 07:45 PM   #1
sd_read
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Rep: Reputation: 0
using a shell script to close a minicom log file and open a new one.


Hi,

I have built a microprocessor board which will allow me to log my hydro usage. It involves a photo diode on my hydro meter which counts flashes.

Every 10 minutes I send the kWh out the serial port. Obviously I am power conscious and so I am connecting this to one of my servers which is on anyway.

I am then using minicom to collect the data but it is very hard to look at as one big fat file. What I want to do is have a cron job call a shell script to close the previous days log file and then start up another one for the present day.

So, at say 12:05 am, close off the present minicom log file and start a new file using the new date as the file name.

So, I will have one file per day.

I did figure out how to start minicom and start logging with a file name made from the present date.

Here is my script so far:

Code:
#!/bin/bash
# By -sdr- 14/08/2011
# Revision 1.0 14/08/2011

# Make script crontab friendly:
cd $(dirname $0)

# datadir is the directory you want podcasts saved to:
datadir=$(date +%Y-%m-%d_%H:%M:%S)

# start minicom with file name of todays date
minicom -C $datadir.txt
What I don't know how to do is cleanly close the log file and shut down minicom.

Any help is greatly appreciated.

Thank you - Steve

Last edited by sd_read; 08-16-2011 at 05:02 PM.
 
Old 08-16-2011, 02:30 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
There's probably no need to reinvent the wheel. Have a look at logrotate.

Also, please use [code][/code] tags around your code, to preserve formatting and to improve readability.
 
Old 08-16-2011, 05:04 PM   #3
sd_read
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Hi David,

You are a genius!

I never thought about logrotate nor did I realise how it works and can apply to minicom.

Thank you for your help- Steve

PS- Thanks for the tip on [CODE]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to create log file in shell script ramecare Linux - Server 12 05-07-2011 08:54 AM
Shell script to Continuously scan a log file for success novice82 Linux - Newbie 4 10-09-2009 03:20 AM
shell script to monitor log file calipryss Linux - Newbie 14 08-05-2008 11:46 PM
Filtering a CSV file from web log with shell script? Micro420 Programming 8 08-22-2007 04:13 AM
Log all of a shell script's I/O to the console and a file trevelluk Programming 8 04-18-2005 02:40 PM


All times are GMT -5. The time now is 03:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration