[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: implicit linkage (was: Re: Effectively criticizing decisions you disagree with in Debian)



Hmm. Let's comment that for people newer to scripting than I am.

On Sun, Oct 12, 2014 at 6:28 AM, Steve Litt <slitt@troubleshooters.com> wrote:
> [...]
> Daemontools runscripts are incredibly simple shellscripts, that I'm
> sure you could write no sweat except in very wierd edge cases. Here's
> my run script for my home-grown cron substitute:
>
> ======================================================
> #!/bin/sh
>
> ####### DON'T START littcrond UNTIL THE NETWORK'S UP #######
> pingaddr=8.8.8.8
> pingaddr=192.168.something

Binding a value to pingaddr twice?

> echo littcrond checking network 1>&2

echo is kind of like a basic print statement, except you sort of don't
need quotes. littcrond , checking , and network are passed as three
separate tokens to echo, which sees each one as a string literal
(because it doesn't recognize any of them as something defined) and
echoed separately literally.

The clot 1>&2 , (man bash, / search for redirect) redirects  stderr to
stdout for the echo.

> while ! ping -q -c1 $pingaddr > /dev/null; do

between the while and the semicolon is the condition. Between the do
and the done are the commands to execute in the loop. The loop
condition is tested at the start of the loop.

Exclamation mark inverts the test.

ping returns a success value.

In shell, success is zero, failure non-zero. That allows failure to be
an error code, but it also surprises you if you forget that it's the
reverse of C and many other languages. This doesn't really matter
here, because ! expects the shell version of a boolean flag, so it
does what it should.

man ping tells us -q is "quiet" and -c1 says stop after 1 packet.

$pingaddr refers through the name pingaddr, which was last bound to a
LAN local address above, essentially as if pingaddr were a variable.

> sleep 1
> echo littcrond REchecking network 1>&2
> done

So the meat of the loop is in the test, and the body we just sleep and
so we are waiting/checking.

> ####### RUN THE DAEMON #######
> exec envuidgid slitt envdir ./env setuidgid slitt \
> /d/at/python/littcron/littcron.py \
> /d/at/python/littcron/crontab

man exec for clues to that, understand that littcron.py is Steve's
special cron (right, Steve?), and that he is setting up a special
environment for things and there's other stuff there that I can only
guess at, not having the code to littcron, I think. So I'll punt here.

> ======================================================

--
Joel Rees

Be careful where you see conspiracy.
Look first in your own heart,
and ask yourself if you are not your own worst enemy.


Reply to: