Professional Web Applications Themes

Help - a question on Unix/Linux script - UNIX Programming

Hi, This is a newbi question on Unix/Linux script. Your help would be appreciated. I need to run a utility (#./my_util -p some_value) for 10 times, and each time a different value increased by 1 needs to be passed to the utility. The simple script to run my_util 10 times with the same parameter (-p 100) may look like this: for 1 2 3 4 5 6 7 8 9 10 do ../my_util -p 100 done The question is how I can use a different value (from 100 to 109) for each instance of my_util in the script? Thanks, T....

  1. #1

    Default Help - a question on Unix/Linux script

    Hi,

    This is a newbi question on Unix/Linux script. Your help would be
    appreciated.

    I need to run a utility (#./my_util -p some_value) for 10 times, and each
    time a different value increased by 1 needs to be passed to the utility.

    The simple script to run my_util 10 times with the same parameter (-p 100)
    may look like this:

    for 1 2 3 4 5 6 7 8 9 10
    do
    ../my_util -p 100
    done

    The question is how I can use a different value (from 100 to 109) for each
    instance of my_util in the script?

    Thanks,


    T.





    L Guest

  2. #2

    Default Re: Help - a question on Unix/Linux script

    "L" <com> writes:
     

    for i in 100 101 102 ...
    do
    ./my_util -p $i
    done

    --
    Måns Rullgård
    se
    Måns Guest

  3. #3

    Default Re: Help - a question on Unix/Linux script

    In comp.unix.programmer L <com> wrote: 
     
     
     

    Well, the simplest way (in bash etc.) would be

    for i in 100 101 102 103 104 105 106 107 108 109; do
    ./my_util -p $i;
    done

    Of course, there are more fancy ways like

    i=100;
    while [ $i -lt 110 ]; do
    ./my_util -p $i;
    let i+=1;
    done
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ fu-berlin.de
    \__________________________ http://www.toerring.de
    Jens.Toerring@physik.fu-berlin.de Guest

  4. #4

    Default Re: Help - a question on Unix/Linux script

    Thanks so much.

    my_util runs for 10 sec once starts. Since I need to run 10 instances of
    my_util concurrently (not one by one), so I create a script (go_client)
    using & like this:

    for i in 100 101 102 103 104 105 106 107 108 109;
    do
    ./my_util -p $i &;
    done

    When invoking this script, I got error msgs:
    ../go_client: line 3: syntax error near unexpected token ';'
    ../go_client: line 3: './mu_util -p $i &;'

    What do I miss?

    Thanks,


    T.



    L Guest

  5. #5

    Default Re: Help - a question on Unix/Linux script



    L wrote: 

    remove ';' from the end of line 3
    Lorinczy Guest

  6. #6

    Default Re: Help - a question on Unix/Linux script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    L <com> wrote:

    [..]
     

    [..]
     
     

    for i in `seq 100 109`;do ./my_util -p $i;done

    Hint:
    man seq

    Good luck

    - --
    Michael Heiming - RHCE (GPG-Key ID: 0xEDD27B94)

    Remove +SIGNS and www. if you expect an answer, sorry for
    inconvenience, but I get tons of spam.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAPQg/AkPEju3Se5QRAoR1AJ44rAbZYXejZjGKOyvMicc2+6k0UwCdEr AN
    RBztIxh8lD/LD3S4lXbPsdQ=
    =JLCt
    -----END PGP SIGNATURE-----
    Michael Guest

  7. #7

    Default Re: Help - a question on Unix/Linux script

    On Wed, 25 Feb 2004 at 20:40 GMT, Michael Heiming wrote: 
    >
    > for i in `seq 100 109`;do ./my_util -p $i;done
    >
    > Hint:
    > man seq[/ref]

    Unfortunately, seq is not available on many systems.

    The portable way to do it is:

    first=100
    last=109
    num=$first
    while [ $num -le $last ]
    do
    : do whatever
    num=$(( $num + 1 )) ## if not a POSIX shell, use num=`expr $num + 1`
    done

    If there's never any need for any other numbers, one can do:

    for num in 100 101 102 103 104 105 106 107 108 109
    do
    : whatever
    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
    Chris Guest

  8. #8

    Default Re: Help - a question on Unix/Linux script

    Thanks for the info.

    T.

    "Chris F.A. Johnson" <com> wrote in message
    news:c1j5b7$1j6n4v$news.uni-berlin.de... [/ref][/ref]
    each 
    > >
    > > for i in `seq 100 109`;do ./my_util -p $i;done
    > >
    > > Hint:
    > > man seq[/ref]
    >
    > Unfortunately, seq is not available on many systems.
    >
    > The portable way to do it is:
    >
    > first=100
    > last=109
    > num=$first
    > while [ $num -le $last ]
    > do
    > : do whatever
    > num=$(( $num + 1 )) ## if not a POSIX shell, use num=`expr $num + 1`
    > done
    >
    > If there's never any need for any other numbers, one can do:
    >
    > for num in 100 101 102 103 104 105 106 107 108 109
    > do
    > : whatever
    > 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[/ref]


    L Guest

  9. #9

    Default Re: Help - a question on Unix/Linux script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Chris F.A. Johnson <com> wrote: 
    > >
    > > for i in `seq 100 109`;do ./my_util -p $i;done
    > >
    > > Hint:
    > > man seq[/ref][/ref]
     

    Strange, thought I would have used it on various *nix in the past.
    Your millage may vary.

    - --
    Michael Heiming (GPG-Key ID: 0xEDD27B94)

    Remove +SIGNS and www. if you expect an answer, sorry for
    inconvenience, but I get tons of spam.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAPRvkAkPEju3Se5QRAuo5AJ91miN8e26jeJekPoCZv4 wEKONRgACfSwWD
    Iqb9cWB4c7IoX3RNEFZrjgg=
    =NGl0
    -----END PGP SIGNATURE-----
    Michael Guest

  10. #10

    Default Re: Help - a question on Unix/Linux script

    "L" <com> wrote in message news:<c1il6t$1jm7kk$news.uni-berlin.de>... 

    no one seems to have mentioned doing it like this (in bash at least!)

    for((i=100;i<=109;i++))
    do
    .....
    done

    which is more c like so i sort of prefer it.
    Alex Guest

  11. #11

    Default Re: Help - a question on Unix/Linux script

    Thanks!

    I'm a C programmer too, the syntaxt of the scripts looks bit different.
    Take "while [ $i -lt 123 ]" as an example, all spaces seem MUST, which is
    not true in C. I need some time to get familiar with that.

    Thanks,


    T.


    "Alex Sisson" <org> wrote in message
    news:google.com... 
    news:<c1il6t$1jm7kk$news.uni-berlin.de>... [/ref]
    each [/ref]
    100) [/ref]
    each 
    >
    > no one seems to have mentioned doing it like this (in bash at least!)
    >
    > for((i=100;i<=109;i++))
    > do
    > .....
    > done
    >
    > which is more c like so i sort of prefer it.[/ref]


    L Guest

  12. #12

    Default Re: Help - a question on Unix/Linux script

    "L" <com> writes:
     

    That's right. The reason is that "[" is a program that takes
    arguments the usual way.

    --
    Måns Rullgård
    se
    Måns Guest

Similar Threads

  1. Replies: 3
    Last Post: May 26th, 12:15 AM
  2. MSN Zone on Linux/Unix
    By Wally Sanford in forum Linux / Unix Administration
    Replies: 0
    Last Post: October 9th, 10:34 PM
  3. Replies: 8
    Last Post: September 29th, 12:56 AM
  4. question on a unix script
    By Fletcher Glenn in forum UNIX Programming
    Replies: 0
    Last Post: June 26th, 09:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139