1

I want to use Munin to show the wave of my data. I get the data from ttyACM0, it's an Arduino UNO. I use shell script. But I got a problem, I cannot ues 'cat /dev/ttyACM0' to get the data. Here is the problem, the programme stopped at 'cat /dev/ttyACM0',

+ . /usr/share/munin/plugins/plugin.sh
+ '[' '' = autoconf ']'
+ '[' '' = config ']'
++ cat /dev/ttyACM0

Sometimes there is another problem, it's that 'LINE = $(cat /dev/ttyACM0 | awk -F: '{print $2}')' command not found. Anyone has an idea? Thanks very much.

Here is a part of my code,

if [ "$1" = "config" ]; then
    echo 'graph_title Temperature of board'
    echo 'graph_args --base 1000 -l 0'
    echo 'graph_vlabel temperature(°C)'
    echo 'graph_category temperature'
    echo 'graph_scale no'
    echo 'graph_period second'
    echo 'graph_info This graph shows the temperature of board'
    LINE = $(cat /dev/ttyACM0 | awk -F: '{print $2}')

    for i in 0 1 2 3 4; do
        case $i in
            1)
            TYPE="Under PCB"
            ;;
            2)
            TYPE="HDD"
            ;;
            3)
            TYPE="PHY"
            ;;
            4)
            TYPE="CPU"
            ;;
            5)
            TYPE="Ambience"
            ;;
        esac
        name=$(clean_name $TYPE)
        if ["$TYPE" != "NA"]; then 
            echo "temp_$name.label $TYPE";
        fi
    done
    exit 0
 fi

LINE = $(cat /dev/ttyACM0 | awk -F: '{print $2}')
for i in 0 1 2 3 4; do
    case $i in
        1)
        TYPE="Under PCB"
        VALUE=$(echo "$LINE" | awk '{print $1}')
        ;;
        2)
        TYPE="HDD"
        VALUE=$(echo "$LINE" | awk '{print $2}')
        ;;
        3)
        TYPE="PHY"
        VALUE=$(echo "$LINE" | awk '{print $3}')
        ;;
        4)
        TYPE="CPU"
        VALUE=$(echo "$LINE" | awk '{print $4}')
        ;;
        5)
        TYPE="Ambience"
        VALUE=$(echo "$LINE" | awk '{print $5}')
        ;;
    esac

    name=$(clean_name $TYPE)
    if ["$TYPE" != "NA"]; then
        echo "temp_$name.value $VALUE";
    fi
done
haoX
  • 29
  • 3

2 Answers2

2

Remove the spaces on either side of = sign. They are not permitted in variable assignment.

Change it to:

LINE=$(cat /dev/ttyACM0 | awk -F: '{print $2}')
dogbane
  • 266,786
  • 75
  • 396
  • 414
2

The problem with the LINE error is that you have spaces around the '=' character. It must be LINE=....

If /dev/ttyACM0 is a device that does not indicate EOF, then it will wait for more to read and the awk will wait for an EOF that never comes. What exactly do you expect /dev/ttyACM0 to produce? What happens if you type cat /dev/ttyACM0 on the console?

Further note the useless use of cat. Better use

LINE=$(awk -F: '{print $2}' /dev/ttyACM0)

And you must add space in if ["$TYPE" != "NA"]; then so it reads

if [ "$TYPE" != "NA" ]; then
Jens
  • 69,818
  • 15
  • 125
  • 179