You are not logged in.

#1 2008-12-11 21:56:10

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Catching SIGUSR1 in a Script?

Following on from my other thread about seamless audio recording, I think I have the seamless part figured out (thanks to a fifo buffer smile), but my issue now is that I need the output filename to change every hour on the hour, not just an hour from when the script started.

For example:
Script starts at 9:20am. I need it to change filename at 10:00am, not at 10:20am. So the first recording will be 40 minutes, and everything after will be the full hour.

This is the script at the moment, sleeping for the full hour though. Ideally I'd like to be able to catch SIGUSR1 in the script and then change filenames at that time (ie, do the kill line and reloop). That way I could just start the script, then crontab a `kill -SIGUSR1 <pid>` every hour...

mkfifo /tmp/audio
arecord --format cd --file-type raw > /tmp/audio
while true ; do
   FNAME=`date +%Y%m%d-%a-%H00_%s`
   oggenc /tmp/audio -r -o $FNAME.ogg
   OGGENC_PID=$!
   sleep 3600
   kill $OGGENC_PID
done

Any ideas, thoughts, suggestions or solutions welcomed smile

Offline

#2 2008-12-11 22:24:34

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: Catching SIGUSR1 in a Script?

Why not just look at the start time minutes and subtract the difference between that and 60 in seconds from 3600 only for the first loop? Then, each loop would be the full 3600 seconds.

Offline

#3 2008-12-11 22:30:40

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Catching SIGUSR1 in a Script?

Use "trap".


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#4 2008-12-12 02:14:41

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Catching SIGUSR1 in a Script?

Thanks guys - I've managed to get this going in perl using it's trap handling and all is good smile

Offline

#5 2008-12-12 02:33:23

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Catching SIGUSR1 in a Script?

When you have everything completed, would you please post your final result? This problem ran through my head for over an hour last night after reading the originating thread. I'd love to see the final.

Offline

#6 2008-12-12 03:15:48

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Catching SIGUSR1 in a Script?

And if you can generalize it, post it to the script wiki. big_smile


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#7 2008-12-12 03:54:54

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: Catching SIGUSR1 in a Script?

BTW, with epoch time you can do some neat things using modulo math to get what you want:

sleep $(expr 3600 - $(date +%s) % 3600)

Using that line will always sleep until the next hour, on the hour.

Offline

#8 2008-12-12 04:46:06

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Catching SIGUSR1 in a Script?

I'm getting there... I'll definitely post the outcome if there's interest smile

The cycle filename on the hour problem has been dealt with by using perl and SIGUSR1... Here's where I'm up to atm:
http://pastebin.com/m73d83a50

I've got a completely new problem now:
http://bbs.archlinux.org/viewtopic.php?pid=462663

Offline

Board footer

Powered by FluxBB