Search code examples
bashshellcommand-line-argumentsbackground-process

Bash: receive messages from background process


I'm sending data via cansend to vcan0, at the same time I'm listening to messages that has been send to vcan0 via candump vcan0.

For some reason, i won't receive any messages, when sending data to vcan0 through the script, but when i send data through terminal, the script receives data, somehow.

cansend vcan0 004#0152FEE400000000 # sending data to vcan0
while true;
do
  msg_candump=$(candump vcan0) # read vcan0
  if [[ ${#msg_candump} > 1 ]]; then #received msg
    echo $msg_candump
  fi
done

Solution

  • this did the job:

    while true;
    do
      cansend vcan0 '004#0152FEE400000000'
      sleep 1
      msg_candump="$(candump vcan0 -n 1)" # read vcan0
      if [[ ${#msg_candump} > 1 ]]; then #received msg
        echo $msg_candump
        msg_candump=${msg_candump// /} # leerzeichen entfernen
        msg_candump=${msg_candump:19:8} # substring holen
        msg_candump=${msg_candump,,} #lowercase
        if [[ $msg_candump != `git log -1 --format="%h"`0 ]]; then
          echo "git pull"
          #git pull
          break
        fi
      fi
      sleep 0.025
    done