Terminate Scripted Minicom Session

If you start a minicom session with the -S you can automate a minicom session with runscript.  This starts two separate processes, the minicom process and the runscript process.  If you want to close the minicom session when the script is finished, simply calling exit in the runscript isn't enough.

To End the minicom session you have to kill the minicom process, using the ! operator within the script to execute an external command.

The easiest method is to run

! killall minicom

This isn't recommended if you might have multiple minicom processes running.  A better way is to use pkill to target the correct minicom session

! pkill -f "^minicom conf_file -S script_file$"

Where conf_file and script_file are the names of your minicom files.  pkill uses a regex to kill the process that you specify.

Of course to use pkill you have to be able to generate the script file dynamically, or make sure you always call minicom with the same command when you use it.  Here's how I use a bash script to generate the script and call minicom.

#!/bin/bash

minicom_profile="my_conf"
minicom_file="my_runscript"
minicom_command="minicom $minicom_profile -S $minicom_file"
pkill_command="\"^${minicom_command}$\""

cat > $minicom_file << EOF
send ""

expect {
    "Press any key"
}
send "a"

! pkill -f $pkill_command
exit 0
EOF

$minicom_command

Comments

Popular posts from this blog

CodinGame: Building an AI to play (and win) at "Penguins"

Starcraft 2 Galaxy Map Editor - Change the Size of a Building