I want to debug root-run python scripts via PyDev + eclipse. I also would like to avoid pip entirely. Via python subprocess I would like to send some commands to postgres, but that actually would require running python script as root (then it works).
example: consider this working script, which tries to interact with postgres + avoiding pip packages (as non-root it hangs indefinately):
ok that was in 2022 https://arstechnica.com/information-technology/2022/08/10-malicious-python-packages-exposed-in-latest-repository-attack/ and the those devs are probably trustworthy https://pypi.org/user/jerickso/ https://pypi.org/user/piro/ but still X-D
Is it so hard?
hostnamectl |grep Op; # tested on, Debian is more minimalistic faster!!! :D
Operating System: Ubuntu 22.04.4 LTS
vim /home/user/git/test/test_db.py
import subprocess
print("=== python: how to interact with postgres without 3rd party pip packages v1.0 ===")
# Define the command to be executed
command = 'sudo -u postgres psql -c "SELECT version();"'
# Execute the command using subprocess
try:
result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
print("Output:")
print(result.stdout)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
print(f"Command output (stderr): {e.stderr}")
How to elegantly go about it?
PS: also already meddled with sudo
currently the only working solution :D
start eclipse as root without sudo
vim /script/start_eclipse_as_root.sh
#!/bin/bash
export DISPLAY=':0.0'
cp -v /home/user/.Xauthority /root/.Xauthority
/home/user/eclipse/eclipse/eclipse
Also: it would probably be better to use pure (root run) bash for the task of viewing hardware info that only root can access (logical volumes)
Wondering if there is a more elegant way.
PS: please keep stackoverflow.com as simple as possible.
sudoorpsql. Of course you'll need a driver;psycopg2is the best but there're alsoPyGreSQL,py-postgresqlandpg8000.