w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
awk on debian squeeze versus debian wheezy

I fixed the triple comma issue with a work around:

   
OUTPUT_DIR=/share/es-ops/Build_Farm_Reports/WorkSpace_Reports
    BASE=/export/ws
    TODAY=`date +"%m-%d-%y"`
    HOSTNAME=`hostname`
    WORKSPACES=( "bob_avail" "bob_used" "mel_avail" "mel_used"
"sideshow-ws2_avail" "sideshow-ws2_used" )
    if ! [ -f $OUTPUT_DIR/$HOSTNAME.csv ] && [ $HOSTNAME ==
"sideshow" ]; then
    echo "$HOSTNAME" >  $OUTPUT_DIR/$HOSTNAME.csv # with a linebreak
    separator="," # defined empty for the first value
    for v in "${WORKSPACES[@]}"
    do
      echo -n "$separator$v" >> $OUTPUT_DIR/$HOSTNAME.csv # append,
concatenated, the separator and the value to the file
      #separator="," # comma for the next values
    done
    echo >> $OUTPUT_DIR/$HOSTNAME.csv # add a linebreak (if you want
it)
    WORKSPACES2=( "bob" "mel" "sideshow-ws2" )
    df -m "${WORKSPACES2[@]/#//export/ws/}" | awk '
        BEGIN  { "date +'%m-%d-%y'" | getline date;
                 printf "%s",date }
        NR > 1 { printf ",%s,%s", $3, $2; }
        END    { printf "
"}' >> "$OUTPUT_DIR/$HOSTNAME.csv"
    elif [ $OUTPUT_DIR/$HOSTNAME.csv ] && [ $HOSTNAME == "sideshow"
]; then
    WORKSPACES2=( "bob" "mel" "sideshow-ws2" )
    df -m "${WORKSPACES2[@]/#//export/ws/}" | awk '
        BEGIN  { "date +'%m-%d-%y'" | getline date;
                 printf "%s",date }
        NR > 1 { printf ",%s,%s", $3, $2; }
        END    { printf "
"}' >> "$OUTPUT_DIR/$HOSTNAME.csv"
    else
    :
    fi
    case "$HOSTNAME" in
        simpsons) WORKSPACES=(bart_avail bart_used homer_avail home_used
lisa_avail lisa_used marge_avail marge_used releases_avail releases_used
rt-private_avail rt-private_used simpsons-ws0_ava
    il simpsons-ws0_used simpsons-ws1_avail simpsons-ws1_used
simpsons-ws2_avail simpsons-ws2_used vsimpsons-ws_avail vsimpsons-ws_used)
;;
        moes)     WORKSPACES=(barney_avail barney_used carl_avail carl_used
lenny_avail lenny_used moes-ws2_avail moes-ws2_used) ;;
        flanders) WORKSPACES=(flanders-ws0_avail flanders-ws0_used
flanders-ws1_avail flanders-ws1_used flanders-ws2_avail flanders-ws2_used
maude_avail maude_used ned_avail ned_used rod_avail ro
    d_used todd_avail todd_used to-delete_avail to-delete_used) ;;
    esac
    if ! [ -f $OUTPUT_DIR/$HOSTNAME.csv ] && [ $HOSTNAME ==
`hostname` ]; then
    echo "$HOSTNAME" >  $OUTPUT_DIR/$HOSTNAME.csv # with a linebreak
    separator="," # defined empty for the first value
    for v in "${WORKSPACES[@]}"
    do
      echo -n "$separator$v" >> $OUTPUT_DIR/$HOSTNAME.csv # append,
concatenated, the separator and the value to the file
      #separator="," # comma for the next values
    done
    echo >> $OUTPUT_DIR/$HOSTNAME.csv # add a linebreak (if you want
it)
    case "$HOSTNAME" in
            simpsons) WORKSPACES2=(bart homer lisa marge releases
rt-private simpsons-ws0 simpsons-ws1 simpsons-ws2 vsimpsons-ws) ;;
            moes)     WORKSPACES2=(barney carl lenny moes-ws2) ;;
            flanders) WORKSPACES2=(flanders-ws0 flanders-ws1 flanders-ws2
maude ned rod todd to-delete) ;;
    esac
    df -m "${WORKSPACES2[@]/#//export/ws/}" | awk '
    BEGIN  { "date +'%m-%d-%y'" | getline date;
                 printf "%s",date }
        NR > 1 { printf ",%s,%s", $3, $2; }
        END    { printf "
"}' >> "$OUTPUT_DIR/$HOSTNAME.csv"
    sed -i s/,,,/,/g "$OUTPUT_DIR/$HOSTNAME.csv"
    elif [ $OUTPUT_DIR/$HOSTNAME.csv ] && [ $HOSTNAME == `hostname`
]; then
    case "$HOSTNAME" in
            simpsons) WORKSPACES2=(bart homer lisa marge releases
rt-private simpsons-ws0 simpsons-ws1 simpsons-ws2 vsimpsons-ws) ;;
            moes)     WORKSPACES2=(barney carl lenny moes-ws2) ;;
            flanders) WORKSPACES2=(flanders-ws0 flanders-ws1 flanders-ws2
maude ned rod todd to-delete) ;;
    esac
    df -m "${WORKSPACES2[@]/#//export/ws/}" | awk '
        BEGIN  { "date +'%m-%d-%y'" | getline date;
                 printf "%s",date }
        NR > 1 { printf ",%s,%s", $3, $2; }
        END    { printf "
"}' >> "$OUTPUT_DIR/$HOSTNAME.csv"
    sed -i s/,,,/,/g "$OUTPUT_DIR/$HOSTNAME.csv"
    else
    :
    fi

I just put:

sed -i s/,,,/,/g "$OUTPUT_DIR/$HOSTNAME.csv"

I really wish I would have thought of how to do the awk part that eliminated the triple commas in the first place but at least my script works now.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.