1

I have a script that simply does this:

cat /dev/ttyUSB0 > /home/pi/usb0_$(date +\%Y\%m\%d\%H\%M\%S).txt

It runs great, but I want to create a new file each day instead of one big file.

I thought about using crontab to do this, but I don't know how to get the first day's job to end before starting the next.

2 Answers 2

2

There's the timeout utility in GNU coreutils for exactly that, run:

timeout 86400 cat ... > ...
2
  • For those lacking GNUs, a script cat … > … & sleep 86400; kill %1 should be similar
    – Fox
    Apr 30, 2017 at 18:30
  • The question originally mentioned Linux in passing, and /dev/ttyUSB0 sounds like linux, so I assumed a GNU userspace. :)
    – ilkkachu
    Apr 30, 2017 at 18:59
1

Another option would be to skip the needless complication of killing daily and instead pipe the output to e.g. rotatelog or cronolog that would then daily rotate the output to a new file.

... | ...rotatelogs -l /home/pi/usb0_%Y%m%d 86400

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .