I am trying to edit the motd, but instead of bash scripts I want to use Python Scripts. It turns out, that Python Scripts do not work with imported libraries.
for example, this would work:
#!/usr/bin/env python3
print("Hello")
However, this does not work:
#!/usr/bin/env python3
import psutil
print(f"Users: {len(psutil.users())}")
When using the command sudo update-motd
both scripts work, but when I try to connect via ssh only the upper script works.
I have already checked the following settings of ssh:
in /etc/ssh/sshd_config PrintMotd is enabled:
PrintMotd yes
in /etc/pam.d/ssh I have these settings for motd:
session optional pam_motd.so motd=/run/motd.dynamic
session optional pam_motd.so noupdate
I am using Ubuntu 18.04.3 LTS x86_64
env
? Something like#!/usr/bin/python3
? I'm thinking that the default PATH when you connect via ssh is sending you to a different python version because you're using env and that python version doesn't have the necessary packages for some reason.PYTHONPATH
different for root compared to your non-privileged user(s)?pip3 install psutil
. The commandpython3 -c "import psutil as _; print(_.__path__)"
returns the installation path of psutil which is in my home directory:/home/vulturemox/.local/lib/python3.6/site-packages/psutil
(running it as sudo returns the same path). Is there a better way to install psutil? When I runecho $PYTHONPATH
it returns nothing (regardless of sudo). Should I define PYTHONPATH?python3-psutil
package then it should work with the defaultpython3
from the repo (assuming you haven't done anything rash like remove the defaultpython3
of course).