[K12OSN] bash script help

James P. Kinney III jkinney at localnetsolutions.com
Wed Oct 31 13:08:21 UTC 2007


#!/bin/sh
runforever=1
while [ $runforever ]
do

<stuff>

done

It will chew up resources and spit out the pieces (unless sleep is used
judiciously). Which is why it is best to have it as a cron job run once
a minute. From a sysadmin standpoint, a 30-40 second delay in
notification of a failed service is usually OK. If it's not, that
service needs to be on a dedicated machine running watchdog services.

I have seen wrapper scripts that do something along the lines as above
but use the PID of the service. This can be used to auto-restart a
failed service but it will not detect the crashed service that has a
dangling PID.

On Wed, 2007-10-31 at 07:51 -0600, Doug Simpson wrote:
> Is it just not possible to make a bash script run in a continuous
> loop? 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. No one has offered a solution that includes that. . .
> 
> 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."
> 
> 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. 
> 
> What does this line do?:
>   done </path/to/file
> 
> Thanks for your assistance!
> 
> 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/30/2007 1:04 PM >>>
> Doug Simpson wrote:
> 
> > I have a script that I am trying to get to work and I can't get it
> right. It is a script that will write the names of offline servers to
> a textfile.
> > 
> > As it is, it only does the first server and repeats, *unless* the
> first server is not online, in which it writes to the file and then
> goes on to the next one.
> > How can I make it continue through the script regardless of whether
> or not each server is online, but still echo the text to the file if
> it finds one offline and then restart at the top of the list again?
> > 
> > The script follows.
> > 
> > ******************************************
> > #!/bin/bash
> > while (true)
> > do
> > #sleep 30
> > if ping -i 3 -c 3 10.40.12.56
> > then
> > continue
> > else
> > echo "Doug's workstation is offline. Please check it!"
> >>serverdown.txt
> > fi
> 
> [..lots of repeated stuff...]
> 
> 
> 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
>     lesmikesell at gmail.com 
> 
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com 
> https://www.redhat.com/mailman/listinfo/k12osn 
> For more info see <http://www.k12os.org>
> 
> 
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
> 
-- 
James P. Kinney III          
CEO & Director of Engineering 
Local Net Solutions,LLC        
770-493-8244                    
http://www.localnetsolutions.com

GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics)
<jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/k12osn/attachments/20071031/eee6a61f/attachment.sig>


More information about the K12OSN mailing list