Running a script every second
Yan Seiner
yan at seiner.com
Thu Mar 6 14:25:49 UTC 2014
On 03/05/2014 10:49 PM, Harald Becker wrote:
> Hi Yan !
>
> On 05-03-2014 09:14 Yan Seiner <yan at seiner.com> wrote:
>> I am trying to run a script every second.
> Beside what Laurent told about using sleep, etc.
>
>> first script (the one that does the work)
>>
>> trap 'update' HUP
>> mknod /tmp/dummyfifo p
>> while true; do
>> read < /tmp/dummyfifo > /dev/null 2>&1
>> done
>> The problem is that the 'read' generates a
>> /usr/bin/update: line 1: can't open /tmp/dummyfifo: Interrupted
>> system call
> The reason for this is you create your pipe once, but open it
> again at every iteration of the loop.
>
> Try the following:
>
> mknod /tmp/dummyfifo p
> exec 0</tmp/dummyfifo 1>/dev/null 2>&1
> while true; do
> read
> done
>
> This opens the fifo once and assigns it for stdin. After that it
> stays open until the first script is terminated in any way.
>
> In addition stdout *AND* stderr are redirected to /dev/null for
> all following commands in the script, so you need to redirect to
> any file or tty when you want do display something.
Thanks!
I like it. My solution leaves 'cat' processes behind if the script gets
killed. Usually not a problem since it's only invoked at boot.
More information about the busybox
mailing list