[K12OSN] bash script help

Doug Simpson simpsond at leopards.k12.ar.us
Thu Nov 1 18:28:13 UTC 2007


Great!

I'll try this one!

Thanks. . .

Doug

Doug Simpson
Technology Specialist
De Queen Public Schools
De Queen, AR
simpsond at leopards.k12.ar.us
>>> Les Mikesell <les at futuresource.com> 10/31/07 7:23 AM >>>
Doug Simpson wrote:
> Is it just not possible to make a bash script run in a continuous loop?

Yes, note the outer loop of
  while :
   do
[...]
   done
The : statement does nothing but evaluates 'true' so the loop runs forever.

> Your solution looks to be about the easiest to do, but, like the rest,
 > has no provision for the "restart at the top of the list again" part.

Try it. It will wait 30 seconds after it restarts the loop.

> In your solution, would I need the text to log in quotes if it were more than one word so it wouldn't think it was more than one variable?
> 
> like:
> 10.40.12.3 "This hostname is down."

In a read statement, the line is split on white space (actually $IFS so 
it coud be changed) and assigned to the variables in the list.  All 
remaining variables go to the last variable.  So you don't need to 
quote, although multiple spaces might get collapsed to one if you don't 
quote the variable in the echo like "$TEXT"

> And, will it not report anything if the host is *not* down? For the
 > purpose, I need it to sit there quietly running until it sees that a
> host is actually down before it takes any action. Then it reports,
 > and continues on to the next one and so on.

Yes the || construct means 'or' and the right side won't happen unless 
the left side fails (returns a non-zero status).

> What does this line do?:
>   done </path> I'd make a text file in the form:
> 
> ip_address <white space> text to log
> 
> And use a script like:
> 
> #!/bin/bash
> while :
>   sleep 30
>   do
>   while read ADD TEXT
>   ping -i 3 -c 3 $ADD || echo $TEXT >>serverdown.txt
>   done </path> done

-- 
   Les Mikesell
    les at futuresource.com

_______________________________________________
K12OSN mailing list
K12OSN at redhat.com
https://www.redhat.com/mailman/listinfo/k12osn
For more info see <http://www.k12os.org>





More information about the K12OSN mailing list