[colug-432] tty script to scrutinize

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Sun Aug 8 21:29:44 EDT 2010

What bugs do you see in the script below? 

The script lets me to talk to a raw serial port. 
I seldom do scripts, so I do not know the pitfalls. 
I am most concerned about killing off the background task that 
listens on the serial port. I know the script fails to kill 
the background task if the script receives a -9 signal. 
For the other signals (that I _can_ catch), 
I've tried to make sure that there are no mutex issues. 

   [jep200404 at test ~]$ cat bin/ttycat
   if [ $# -ge 1 ]; then
      echo "Usage: ${0##*/} device"
      echo "where device is serial (RS-232/UART) port"
      echo "E.g., ${0##*/} /dev/ttyS0"
      echo "stdin is copied to device"
      echo "data received from device is copied to stdout"
      exit 1
   # echo "port='$port'"
   stty --file="$port" -parenb cs8 -cstopb raw -crtscts 19200 -hupcl -onlcr -echo -echoe -echoctl -echok -echoke -echonl -echoprt -icanon -iexten -isig
   # stty --file="$port" -parenb cs8 -cstopb raw -crtscts 19200 -hupcl -onlcr -echo -echoe -echoctl -echok -echoke -echonl -echoprt -icanon -iexten -isig ixoff ixon
   trap 'signalcaught=1' 0 HUP INT QUIT TERM
   cat <$port &
   # echo "background pid is $! aka $bpid"
      # echo "will kill $bpid"
      kill $bpid
      exit $exitvalue
   trap 'handleSignal' 0 HUP INT QUIT TERM
   if [ $signalcaught -ne 0 ]; then
      # echo caught quick signal
      trap : 0 HUP INT QUIT TERM ;# to avoid re-entrancy issues
   cat - >$port
   exit 0
   [jep200404 at test ~]$ 

By the way, I might move the stty stuff elsewhere, 
but that's minor trivial stuff. 
Turning off the line-at-a-time processing/buffering 
of stdin (except for ^D for EOF and ^C to stop), 
when it's from a console would be nice, 
but I'm just too lazy to fight my way through that. 

I've tried minitel, but it has too much stuff that 
gets in the way. 

Are there better ways for a shell script to talk to a serial 

More information about the colug-432 mailing list