3

I would like to run a python script wich is logging a nmea GPS stream from UART for a drone. And I want to see my scripts output in the terminal. The script starts just fine with the folowing setup:

/etc/systemd/system/gps_log.service

[Unit] 
Description=Startup Script Service
After=multi-user.target 

[Service]
Type=idle
ExecStart=/home/pi/serial_nmealog.sh
WorkingDirectory=/home/pi
User=pi

[Install]
WantedBy=multi-user.target

/home/pi/serial_nmealog.sh:

#!/bin/sh
sleep 10
sudo python3 serial_nmealog.py

Now I want to create a new terminal with screen or tmux to see what my script ist doing. I use the following line in the serial_nmealog.sh file:

sudo screen -dmS gpslog python3 serial_nmealog.py

or

sudo tmux new -s gpslog python3 serial_nmealog.py

But the service is always stops running. When I type sudo systemctl status gps_log.service I get:

for sudo screen -dmS gpslog python3 serial_nmealog.py in serial_nmealog.sh

● gps_log.service - Startup Script Service
   Loaded: loaded (/etc/systemd/system/gps_log.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2018-03-04 11:42:12 UTC; 1min 37s ago
  Process: 1373 ExecStart=/home/pi/serial_nmealog.sh (code=exited, status=0/SUCCESS)
 Main PID: 1373 (code=exited, status=0/SUCCESS)

Mar 04 11:42:01 raspberrypi systemd[1]: Started Startup Script Service.
Mar 04 11:42:12 raspberrypi sudo[1378]:       pi : TTY=unknown ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/screen -dmS gpslog python3 serial_nmealog.py
Mar 04 11:42:12 raspberrypi sudo[1378]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 04 11:42:12 raspberrypi sudo[1378]: pam_unix(sudo:session): session closed for user root

for sudo tmux new -s gpslog python3 serial_nmealog.py in serial_nmealog.sh

● gps_log.service - Startup Script Service
   Loaded: loaded (/etc/systemd/system/gps_log.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2018-03-04 11:24:17 UTC; 1s ago
  Process: 1227 ExecStart=/home/pi/serial_nmealog.sh (code=exited, status=0/SUCCESS)
 Main PID: 1227 (code=exited, status=0/SUCCESS)

Mar 04 11:24:07 raspberrypi systemd[1]: Started Startup Script Service.
Mar 04 11:24:17 raspberrypi sudo[1241]:       pi : TTY=unknown ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/tmux new-session -s pi -d gpslog python3 serial_nmea
Mar 04 11:24:17 raspberrypi sudo[1241]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 04 11:24:17 raspberrypi sudo[1241]: pam_unix(sudo:session): session closed for user root

I also tried to do it with rc.local at startup. But it does not work. What am I missing and how can I make it possible to establish an new terminal session with which I can interact via ssh?

Hans Jürgen
  • 53
  • 1
  • 7

1 Answers1

3

Modify /home/pi/serial_nmealog.py so that it logs to syslog. You can configure syslog so that serial_nmealog has its own log file, if you want. Then you can connect with ssh and tail that logfile. There is no way to "interact" with serial_nmealog.py unless it has itself made provisions for that.

BTW, I think you can safely drop the sudo from /home/pi/serial_nmealog.sh, as far as I can see, you're already root.

Gerard H. Pille
  • 461
  • 2
  • 5