SHARE
TWEET

Untitled

a guest Mar 29th, 2016 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mtaylor:~ Matt$ cat usb-serial.sh
  2. #!/bin/sh
  3. # By Matt Taylor.
  4.  
  5. DEV=`ls /dev/tty.usb*|head -n1`
  6.  
  7. if [ -z $DEV ]; then
  8.     echo "Error: USB to Serial device not found in /dev/tty.* - please make sure it's connected"
  9.     exit
  10. else
  11.     echo "Device found: $DEV"
  12. fi
  13.  
  14. if [ `ps a |  grep 'dev/tty.'| grep -v 'grep' | awk '{print$1}'|wc -l` -gt 0 ]; then
  15.     read -p "Error: $DEV is currently in use, kill existing sessions? [y/n] " CHECK
  16.     if [ $CHECK == "y" ]; then
  17.         echo "Killing existing pids.."
  18.         ps a |  grep 'dev/tty.'| grep -v 'grep' | awk '{print$1}' | xargs kill -9
  19.         screen -wipe
  20.     else
  21.         echo "Exiting"
  22.         exit
  23.     fi
  24. fi
  25.  
  26. if [ -z $1 ]; then
  27.     echo "Baud rates: 4800 9600 19200 38400 57600 115200 31250"
  28.     read -p "What baud rate do you want to use? " BAUD
  29. else
  30.     BAUD=$1
  31. fi
  32.  
  33. screen -U $DEV $BAUD
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top