0

I need to do about a 500k translation of objectids obtained through SNMP of a new switch in a project. this quantity of work can be done only through a script, so I wrote this short bash script to do the job but I'm getting an error "command substitution: line 33: syntax error near unexpected token '&' This is the bash script:

    #! /bin/bash
    #...some code to check arguments here

    input=$1
    shift
    output=$1

    #open the connection
    `stty -F /dev/ttyACM0 115200 raw`
    `exec 3</dev/ttyACM0>$output` # trying to redirect serial port output to file
    `cat <&3 >> &output`  # trying to append output of serial, ERROR HERE
    while read line;
    do
    echo "getMib $line">/dev/ttyACM0
    done<$input
    echo done with file $input
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Micky
  • 29
  • 5
  • 1
    Lol... Everything is a file in Linux until it is not a file. This is a case where it is no longer a file... What file do you know that loses its data... You have to start the reader for the modem in the background. Then, you write to the modem with the interactive session. I was so disgusted with trying to use the shell to do the simple reader/writer I gave up and moved to a C program. The C program was orders of magnitude easier. – jww Apr 02 '19 at 19:26
  • -jww can you post a code snippet? – Micky Apr 02 '19 at 19:47
  • Shouldn't `&output` be `$output`, like it is in the line above? – Ben Voigt Apr 02 '19 at 19:50
  • Ben Voigt that is correct, that escaped me..tomorrow in the lab, hopefully it works – Micky Apr 02 '19 at 20:00
  • See [Reading and writing to serial port in C on Linux](https://stackoverflow.com/a/18134892/608639) and friends. Just open `/dev/ttyACM0`. – jww Apr 02 '19 at 20:04
  • 1
    You don't want to execute the strings printed by those commands, so you should remove all the backticks. This should fix the issue as well, because `cat` and its redirect is running in a different subshell from where you're setting up the input redirect. – l0b0 Apr 03 '19 at 00:57

0 Answers0