4

I have a minicom script which sends some commands via serial and expects something back(which works) but im having trouble exiting the minicom screen.

Below is the minicom script:

success1:    
   print \nSuccessfully received running!
   send "exit" 
   exit 0

success2:
   print \nSuccessfully received degrading!
   ! killall -9 minicom
   exit

I was using ! killall -9 minicom which is recommended on their documentation but unfortunately, when running the script on Jenkins, it fails due to exit code 137 (Another process sent a signal 9). However this does exit minicom, just not successfully.

On the other hand, the 'send "exit"' just logs out of the device, and doesnt exit minicom.

How can i exit minicom and receive a 0 exit code?

3 Answers 3

4

you need to feed <stdin> with three characters: <ctrl-A>x<enter>

  • prepare the file escape.txt using vi in order to write ^Ax^M
  • launch minicom script

/bin/rm -f capture.txt; ( minicom -D /dev/ttyUSB0 -S test_minicom.macro -C capture.txt < escape.txt ) ; cat capture.txt

1
  • 1
    Cannot get expected output in capture.txt with the solution, minicom will start a runscript process while the pipe here just terminates minicom directly before runscript runs test_minicom.macro. An improvement for this: { sleep 1; while pgrep runscript > /dev/null; do sleep 1; done; cat escape.txt; } | minicom -D /dev/ttyUSB0 -S test_minicom.macro -C capture.txt.
    – abuccts
    Feb 25, 2022 at 8:00
2

To build on what Diego shared, if you just need to exit minicom without error and don't care about capturing the exit code, build escape.txt as Diego described then you only need to run:

( minicom -D /dev/ttyUSB0 -S test_minicom.macro -C capture.txt < escape.txt )

This proves to be very helpful for automatic provisioning like with Ansible!

1

As an alternative to creating the escape.txt file, you can use echo to send the exit sequence.

Building on the above answers:

$ /bin/rm -f capture.txt; ( echo -ne "\x01x\r" ) | minicom -D /dev/ttyUSB0 -S test_minicom.macro -C capture.txt; cat capture.txt

To break down the echo command a little,

  • -n removes the default line-feed \n
  • -e tells echo to interpret escape sequences
  • \x01 is the escape sequence for ^A (start-of-heading)
  • x tells minicom to exit
  • \r sends a ^M carriage-return

Hex output from echo:

$ echo -ne "\x01x\r" | od -A x -t x1a -v
000000  01  78  0d
       soh   x  cr
000003

Note: If you just want to send some text and don't need the full minicom scripting you can add an extra echo. Sleep may not be needed depending on command run and if you care about output in capture.txt...

$ /bin/rm -f capture.txt; ( echo "poweroff"; sleep 1; echo -ne "\x01x\r" ) | minicom -D /dev/ttyUSB0 -C capture.txt; cat capture.txt
1
  • 1
    This should be the top answer. You can further improve the code with a temp output file created with mktemp to avoid conflicts.
    – DadiBit
    Mar 18 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.