[Lvlug] assigning multiple returns
Linc Fessenden
linc at thelinuxlink.net
Fri Apr 9 21:00:21 EDT 2004
On Fri, 9 Apr 2004 20:16:01 -0400
Mark <mstanley at technologist.com> wrote:
> On Friday 09 April 2004 19:57, Linc Fessenden wrote:
> > > ---- Incrementing numbers in a loop ----------
> > >
> > > # While loop
> > > i=0
> > > upperlim=10
> > > while [ $i -lt $upperlim ]
> > > do
> > > # mess with $i
> > > i=`expr $i + 1`
> > > done
> >
> > Quicker way to increment numbers:
> > i=0; upperlim=10; while [ $i -lt $upperlim ]; do whatever; ((i++)); done
> >
> > The ((i++)) does an internal bash increment without having to stop and call
> > expr. It's also much shorter to code :-)
>
> Ahh! Nectar of the gods! I was wondering if there weren't a simpler way. Ok
> then you asked for it. :-) Here's the script I was working on and it's now
> clear to me that a review would probably be very beneficial.
>
> It should be easy to spot where I wanted to 'find' and work on the array.
> Note: the name was changed to protect the not-so-innocent.
>
> ----------- Begin Script ---------------------------------
> #!/bin/bash
> # This script copyright 2004 Mark E. Stanley
> # Released under the GNU General Public License 2.0
> #
> # This script was written to work under RH9. I don't
> # expect it will work too many other places. So now we
> # pretend our other server just dies and we want to bring
> # the stand-by up.
>
> DATETIME=`date | cut -d " " -f 2-5`
> LOGMSG="Restored this machine as www.ourserver.com"
>
> # RedHat 9 does all their ethernet magic in the
> # /etc/sysconfig/network-scripts/ directory.
> if [ $PWD == "/etc/sysconfig/network-scripts" ]; then
> echo $DATETIME $LOGMSG >> /var/log/messages
> else
> cd /etc/sysconfig/network-scripts
> echo $DATETIME $LOGMSG >> /var/log/messages
> fi
>
> # Let someone know we've started
> echo "Restoring virtual interfaces...
>
> # Restore all virtual interfaces from the backup directory.
> if [ ! -d ifcfg_files ]; then
> echo "directory missing: /etc/sysconfig/network-scripts/ifcfg_files"
> echo "No backups! Are you really trying to restore this server?"
> exit 1
> else
> /bin/mv -f ifcfg_files/ifcfg-eth0:* ifcfg_files/
> echo "Bringing up virtual interfaces..."
> for ifcfg in ifcfg-eth0:*; do
> /sbin/ifup $ifcfg
> done
> fi
>
> # The list of services that we want to start and
> # roughly the order we want to do it in. I would
> # really like to make sure they start in some
> # controlled order but have heard that can't be
> # guaranteed.
> list="named pop-before-smtp postfix httpd vsftp"
>
> # Now restart each service then add them back into
> # the config so they will restart if the system reboots.
> # This won't affect the REAL ethernet interface as it is
> # already conifigured and running.
> for daemon in $list; do
> `/sbin/service $daemon start &`
> `/sbin/chkconfig --level 2345 $daemon on &`
> done
>
> --
> -Mark Stanley
> _______________________________________________
> Lvlug mailing list
> Lvlug at thelinuxlink.net
> https://www.thelinuxlink.net/mailman/listinfo/lvlug
Looks like it's work to me! How many virtual IP addresses are you running?
--
-Linc Fessenden
In the Beginning there was nothing, which exploded - Yeah right...
More information about the Lvlug
mailing list