Results 1 to 13 of 13
  1. #1
    Join Date
    Sep 2003
    Posts
    12

    Unanswered: while loop on remote server

    How would I go about making a while loop execute on a remote sever and keep doing so until a specific # is met? I've tried this several different ways, using until, adding the dir after the "while". I'm probably missing something here.

    blah="echo * | wc -w"
    m=/tmp/read

    ssh -f -t <hostname>

    cd $m

    while [ "$blah" = 40 ]
    do
    scp *.ask <hostname>:/tmp
    sleep 40
    done

    TIA!!
    Last edited by kasparaitis; 03-09-04 at 16:16.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Try :

    while [ $blah = 40 ]

    or

    while [ "$($blzh)" = 40 ]
    Jean-Pierre.

  3. #3
    Join Date
    Sep 2003
    Posts
    12
    Originally posted by aigles
    Try :

    while [ $blah = 40 ]

    or

    while [ "$($blzh)" = 40 ]

    Thanks! The second while command worked.
    Last edited by kasparaitis; 03-09-04 at 18:36.

  4. #4
    Join Date
    Sep 2003
    Posts
    12
    Another question. Now this script should in theory scp all the files and exit the loop if $blah is = to 40 correct? Otherwise the script will continue in the loop scp'ing files if $blah is less than 40. I'm asking this because my script re-runs even if $blah is = to 40. Did I write this wrong?

    TIA!

    code:

    blah="echo * | wc -w"
    m=/tmp/read

    ssh -f -t <hostname>

    cd $m

    while [ "$($blah)" = 40 ]
    do
    scp *.ask <hostname>:/tmp
    sleep 40
    done

    exit 0

    TIA!!

  5. #5
    Join Date
    Sep 2003
    Posts
    12
    bump

  6. #6
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    The result of the 'echo *|wc -w' containts leading spaces before the count of words. If there are 40 files the resuly is ' 40' and not '40'.

    Modify your test to make numic comparison :
    Code:
    while [ "$(blah)" -eq 40 ]
    Jean-Pierre.

  7. #7
    Join Date
    Sep 2003
    Posts
    12
    Originally posted by aigles
    The result of the 'echo *|wc -w' containts leading spaces before the count of words. If there are 40 files the resuly is ' 40' and not '40'.

    Modify your test to make numic comparison :
    Code:
    while [ "$(blah)" -eq 40 ]
    Thanks! I made the changes you requested and got this:

    <hostname> code
    Begin code processing on\n Thu Mar 11 13:22:55 PST 2004

    Authentication successful.
    Copying files from <hostname>

    code: blah: command not found
    code: [: : integer expression expected
    Copy Complete

    end code processing on\n Thu Mar 11 13:38:28 PST 2004

    -if I use 'until' instead of 'while' it gives the same errors, except it ends up scp'ing the files through and doesn't exit the loop.
    Last edited by kasparaitis; 03-11-04 at 17:42.

  8. #8
    Join Date
    Sep 2003
    Posts
    12
    bump

  9. #9
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Code:
    while [ "$($blah)" -eq 40 ]
    Jean-Pierre.

  10. #10
    Join Date
    Sep 2003
    Posts
    12
    I've tried every one of the following: along with a few others.

    while [ "$($blah) -eq 40 ]
    while [ "$blah -eq 40" ]
    while [ "$(blah) -eq 40 ]

    and so on. With the while [ "$($blah) -eq 40 ] statement I received this error:

    code: [: * | wc -w: integer expression expected
    Copy Complete

  11. #11
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Code:
    while [ "$(eval $blah)" -eq 40 ]
    Jean-Pierre.

  12. #12
    Join Date
    Sep 2003
    Posts
    12
    Originally posted by aigles
    Code:
    while [ "$(eval $blah)" -eq 40 ]
    It gives no error when I use 'eval' but it also does not copy anything over.

  13. #13
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Replace '"$(eval $blah)" by $(echo * | wc -c) in your test.

    Another solution is to create a function instead of using a variable:

    FileCount() {
    echo * | wc -c
    }

    while [ $(FileCount) -eq 40 ]

    Execute your script with the -x option and analyze the result to determine where is the problem.
    Jean-Pierre.

Posting Permissions

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