On Tue, May 24, 2011 at 12:44:42PM +0200, RaSca wrote:
> Il giorno Mar 24 Mag 2011 12:27:04 CET, Dejan Muhamedagic ha scritto:
> > Hi,
> 
> Hi Dejan,
> 
> [...]
> >> # Read parameters
> >> conf_file="/etc/hetzner.cfg"
> >> user=`cat /etc/hetzner.cfg | egrep "^user.*=" | sed 's/^user.*=\ *//g'`
> > Better:
> > user=`sed -n 's/^user.*=\ *//p' /etc/hetzner.cfg`
> 
> Absolutely agree.
> 
> >> pass=`cat /etc/hetzner.cfg | egrep "^pass.*=" | sed 's/^pass.*=\ *//g'`
> >> hetzner_server="https://robot-ws.your-server.de";
> > I assume that this is a well-known URL which doesn't need to be
> > passed as a parameter.
> 
> As far as I know it is the only address, I hard-coded it for this 
> reason, but maybe should be a parameter...

OK.

> >> is_host_up() {
> >>        if [ "$1" != "" ]
> >>         then
> >>          status=`curl -s -u $user:$pass $hetzner_server/server/$1 | sed 
> >> 's/.*status\":"\([A-Za-z]*\)",.*/\1/g'`
> >>          if [ "$status" = "ready" ]
> >>           then
> >>            return 0
> >>           else
> >>            return 1
> >>          fi
> > This if statement can be reduced to (you save 5 lines):
> >           [ "$status" = "ready" ]
> >>         else
> >>          return 1
> >>        fi
> >> }
> 
> You mean the statement should be:
> 
> [ "$status" = "ready" ] && return 0
> return 1
> 
> ?

No, just [ "$status" = "ready" ]. The return is implied at the
end of the function and the code is the exit code of the last
command.

> [...]
> > Again, better (is return code of is_host_up inverted?):
> >       is_host_up "$hostaddress"
> >      exit # this is actually also superfluous, but perhaps better left in
> 
> The action is reset, so if I had success then is_host_up must be NOT 
> ready. Or not?

Right, sorry, I should've turned on my brain beforehand. You can
try this:

        exit $((! $?))

That is going to invert the code.

> [...]
> > Ditto.
> > Good work!
> > Cheers,
> > Dejan
> > P.S. Moving discussion to linux-ha-dev.
> 
> If the compact way is correct, I can modify the script and post it again.

Yes, please do.

Cheers,

Dejan

> -- 
> RaSca
> Mia Mamma Usa Linux: Niente รจ impossibile da capire, se lo spieghi bene!
> ra...@miamammausalinux.org
> http://www.miamammausalinux.org
> 
> _______________________________________________
> Linux-HA mailing list
> linux...@lists.linux-ha.org
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to