WindowsWeenie
WindowsWeenie

Reputation: 369

How to direct all minicom/tmux output to journald

Minicom/tmux can be accessed by a user on the command line, but the content on the screen will get replaced by later content, and the old content is no longer accessible. There's also no logging of timestamps, which journalctl provides. The command:

tmux pipe-pane -o 'cat >>~/tmux.log'

can be used to send output to a log file, but it's not journald and won't have those timestamps. When I try having a service process just call minicom and then attach a tmux session, journalctl contains some output, but like this:

Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: [6B blob data]

Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: Welcome to minicom 2.7.1

Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: OPTIONS: I18n

Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: Compiled on Aug 13 2017, 15:25:34.

Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: Port /dev/ttyACM0

Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: Press CTRL-A Z for help on special keys Jul 25 16:08:29 raspberrypi minicom-monitor.sh[2279]: [6B blob data]

If I add "--output cat", then the "blob data" gets replaced with content like "ESC[0mESC[10mESC[HESC[J" (content that got intermixed with readable content on tmux.log when I piped to there), but there's still none of the readable information I get from minicom if I access it on the console. I would have assumed this was a known use case, but haven't found an example of it being done.

Upvotes: 0

Views: 134

Answers (2)

WindowsWeenie
WindowsWeenie

Reputation: 369

The code I posted here wound up working:

TMUX_PANE=$( sudo tmux list-panes | sed 's/:.*//')
MINICOM_CONFIG="/etc/minicom/minirc.dfl"
if [[ -f $MINICOM_CONFIG ]]
    then  DEVICE=$(cat /etc/minicom/minirc.dfl | sed -n -e 's/.*dev\///p')
fi
sudo tmux pipe-pane -o -t ${TMUX_PANE} "cat /dev/${DEVICE} >> tmux.log

Upvotes: 0

Alcamtar
Alcamtar

Reputation: 1582

Use systemd-cat: it will direct all output directly to the systemd journal.

For example, given a simple script:

array=('line1' 'line2 foo bar' 'line3' 'done')
for a in "${array[@]}" ; do
    echo "$a"
    sleep 1
done

in one terminal window run:

journalctl -f

and in another one run:

bash test.sh | systemd-cat

You will see each line echoed directly into the journal, one per second. It may be useful to prefix each line with a tag for easy identification. You can use sed for this:

bash test.sh | sed -u 's/^/TMUX: /' | systemd-cat

That will produce output like this:

Aug 04 23:18:17 hostname cat[6350]: TMUX: line1
Aug 04 23:18:18 hostname cat[6350]: TMUX: line2 foo bar
Aug 04 23:18:19 hostname cat[6350]: TMUX: line3
Aug 04 23:18:20 hostname cat[6350]: TMUX: done

Now, I haven't tried this with minicom, but using your example I think you could to this:

tmux pipe-pane -o 'sed -u "s/^/TMUX: /" | systemd-cat'

Upvotes: 0

Related Questions