Re: shell script

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 07/16/04


Date: 16 Jul 2004 09:43:07 GMT

On 2004-07-16, tibo wrote:
> Hello.
>
> I'm making a shell script that analyse this result of a command :
>
> bridge name bridge id STP enabled interfaces
> bridge0 8000.0090270d3c6a no eth0
>
> eth1
>
> eth2
> bridge1 8000.000000000000 no
>
> On this result, you can see that interface eth0, eth1 and eth2 are
> attached to bridge0 and that bridge1 has not interfaces attached.
>
> I'd like to do this analyse with a script.
>
> I tried with grep and awk stuff. But I have two problems :
>
> 1)
> On first line, "eth0" is in the 4th column
> On second and third lines, "eth1" and "eth2" are on the first column
>
> 2)
> The other problem is that I'd like to do something like :
>
> scan 4th column or 1st colum (to see "eth0", "eth1", "eth2") of each line
> after bridge0 until I meet "bridge1" on first column. But there's no "until"
> loop in shell script !
>
> Does anyone have an idea, some tip to give me ? Thanks a lot for your
> answers.

man bash:

    while list; do list; done
    until list; do list; done
          The while command continuously executes the do list as long as
          the last command in list returns an exit status of zero. The
          until command is identical to the while command, except that the
          test is negated; the do list is executed as long as the last
          command in list returns a non-zero exit status. The exit status
          of the while and until commands is the exit status of the last
          do list command executed, or zero if none was executed.
    ............

    But I don't think that's what you really want.

    Try (this is just a skeleton):

<COMMAND> | { read header ## discard first line
  while read col1 col2 col3 col4
  do
      case $col1 in
          bridge[0-9]*) : ;;
          *) ;;
      esac
  done
}

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: Newbie help for using multiprocessing and subprocess packages for creating child processes
    ... the first is the conceptual equivalent of executing the ... The first searches for a command in your PATH named ‘ls /path...’. ... where STANAME is a string 4 characters long. ... firing off my shell script: ...
    (comp.lang.python)
  • Re: Newbie help for using multiprocessing and subprocess packages for creating child processes
    ... The first searches for a command in your PATH named ‘ls /path...’. ... where STANAME is a string 4 characters long. ... firing off my shell script: ...
    (comp.lang.python)
  • print subsystem errors
    ... I have an application that executes a shell script to print jobs. ... I can take the same command issued in the shell script; ... ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ...
    (AIX-L)
  • Re: despair
    ... I once tried to write a cd program in Unix. ... Just putting a cd command in a script and then ... hell are you supposed to write shell script macros to run a frequently ... make "$ FOO BAR" a meaningful DCL command. ...
    (comp.os.vms)
  • Re: cron and command quote
    ... if you are going to be using a shell script you have to make sure that it exits properly. ... So, '||' is just as legal as '&&' and would do just as it does on the command line, assuming of course there is nothing found by the grep. ... with && we have execute command1 if it returns true execute command2 ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)