[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [K12OSN] bash script help
- From: Les Mikesell <les futuresource com>
- To: "Support list for open source software in schools." <k12osn redhat com>
- Subject: Re: [K12OSN] bash script help
- Date: Wed, 31 Oct 2007 08:23:04 -0500
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/to/file
It makes the file become stdin to the inner loop so the read statement
consumes lines from the file.
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/to/file
done
--
Les Mikesell
les futuresource com
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]