SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2013-05-14 02:32:21

foozer
Member
Registered: 2013-01-14
Posts: 25

[SOLVED] bash scripting: sleep until SIGUSR1 is given

Hello good people of the Crunchbang forums. I figured if anyone knew the answer to this, they'd be here. Is there a way to do this with bash?

while :; do
        ...
        ...
        << wait for SIGUSR1 >>
done | ...

Some clarification on what I'm trying to do, in case someone knows a different/better solution to this problem:
I'm trying to display mpd's currently playing song in a dzen2 bar. ncmpcpp can execute a command every time the song changes, so my idea was to setup a script called songchange.sh with the above construction and then make ncmpcpp execute "killall -SIGUSR1 songchange.sh". That way it would be much more performant than the usual construction where the script simply sleeps a few seconds every loop.


=======
EDIT:

After a lot of sweat and tears (it was fun as hell) I found a solution:

resume() {
        kill $PID
}
trap resume SIGUSR1

while :; do
        ...
        ...


        sleep 9999 &
        PID=$!
        echo $PID > $HOME/.barpid
        wait $PID 2>/dev/null

done | ...

Last edited by foozer (2013-05-15 16:54:31)

Offline

Be excellent to each other!

#2 2013-05-14 13:44:13

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: [SOLVED] bash scripting: sleep until SIGUSR1 is given

Small detail...

Why not put the trap ... command before the while? That way it only gets executed once, which is enough.

Not that you will notice the difference.

Groeten uit Eernegem  smile

Last edited by xaos52 (2013-05-14 13:45:05)

Offline

#3 2013-05-15 16:56:17

foozer
Member
Registered: 2013-01-14
Posts: 25

Re: [SOLVED] bash scripting: sleep until SIGUSR1 is given

xaos52 wrote:

Small detail...

Why not put the trap ... command before the while? That way it only gets executed once, which is enough.

Not that you will notice the difference.

Groeten uit Eernegem  smile

Hey, countryman!

Doing that gave me funny errors, but only when piping into dzen. Now that I try it again it works, so it must've been something else I was doing.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo