-   Linux - Software (
-   -   using a shell script to close a minicom log file and open a new one. (

sd_read 08-15-2011 07:45 PM

using a shell script to close a minicom log file and open a new one.

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:


# 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

David the H. 08-16-2011 02:30 AM

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.

sd_read 08-16-2011 05:04 PM

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]

All times are GMT -5. The time now is 05:54 PM.