Share this on:

9 comment

  1. Hi,

    Thank you for sharing your knowledge ;-)

    Just a little point of detail about this script:
    the uptime command returns 3 values : 1mn average, 5mn average and 15mn average, not 5mn,10mn and 15mn as you wrote.

  2. The quotes and double-quotes in the corrected lines originally submitted by Anonymous are not simple straight quotes, but curly “smart quotes” (most likely inserted by some MS Word or Outlook editor not designed for code).

    Your script will fail if you simply copy and paste those lines from the web page into your text editor, as curly quotes are not valid delimiters in any shell.

    Here is the corrected script as it is working on my FreeBSD system. I hope this will appear here unaltered:

  3. Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux

    (standard_in) 1: illegal character: |
    (standard_in) 1: parse error
    (standard_in) 1: illegal character: ‘
    (standard_in) 1: illegal character: ‘


    1. Solved.

      #F5M=”$(uptime | awk -F “$FTEXT” ‘{ print $2 }’ | cut -d, -f1) | sed ‘s/ //g'”
      #F10M=”$(uptime | awk -F “$FTEXT” ‘{ print $2 }’ | cut -d, -f2) | sed ‘s/ //g'”
      #F15M=”$(uptime | awk -F “$FTEXT” ‘{ print $2 }’ | cut -d, -f3) | sed ‘s/ //g'”

      lines should be
      F5M=”$(uptime | awk -F “$FTEXT” ‘{ print $2 }’ | cut -d, -f1)”
      # 10 min
      F10M=”$(uptime | awk -F “$FTEXT” ‘{ print $2 }’ | cut -d, -f2)”
      # 15 min
      F15M=”$(uptime | awk -F “$FTEXT” ‘{ print $2 }’ | cut -d, -f3)”

      bash –version
      GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)

      bc confused about comparison results.

      1. The correction in the comment above simply removes the sed command from the end of the pipeline on all three lines:

        | sed ‘s/ //g’

        As it turns out, the error is also corrected by moving the closing right paren so that it includes the sed command within the main pipeline. For example, change:


        (and the same for the F5 and F10 lines, in case you use them)

    Have a question? Post it on our forum!