On Tue, May 24, 2011 at 04:10:17PM +0200, Lars Ellenberg wrote:
> On Tue, May 24, 2011 at 03:41:53PM +0200, Dejan Muhamedagic wrote:
> > 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.
> 
> the shell has ! for that.
>       ! is_host_up

Very well.

> Coffee?

Yes!
I wish the Linbit machine was a bit closer to me, but no such
luck today. Had to stay home today. I'll be over tomorrow.

Cheers,

Dejan

>  ;-)
> 
> -- 
> : Lars Ellenberg
> : LINBIT | Your Way to High Availability
> : DRBD/HA support and consulting http://www.linbit.com
> 
> DRBD® and LINBIT® are registered trademarks of LINBIT, Austria.
> _______________________________________________________
> 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/
_______________________________________________________
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