Repository navigation
trying to get plugin to run a bash script #554
Replies: 1 comment
|
Your Why it does nothingsubprocess.run(["/bin/bash", "/home/rudy/doit.sh", shell=True])With Two correct forms — pick one: # 1) no shell: the recommended one
resultado = subprocess.run(["/bin/bash", "/home/rudy/doit.sh"], capture_output=True, text=True, timeout=60)
# 2) a single string when you really want a shell
resultado = subprocess.run("/home/rudy/doit.sh", shell=True, capture_output=True, text=True, timeout=60)Also check that the file is executable and lives where you think it does: ls -l /home/rudy/doit.sh # needs -rwxr-xr-x, otherwise: chmod +x
head -1 /home/rudy/doit.sh # needs a shebang: #!/usr/bin/env bashTwo things that will bite you next in this plugin1. import os
import subprocess
# ... at the end of generate_image:
image = self.render_image(dimensions, "countdown.html", "countdown.css", template_params)
if day_count <= 0:
marker = "/home/rudy/.doit_done"
if not os.path.exists(marker):
try:
resultado = subprocess.run(
["/bin/bash", "/home/rudy/doit.sh"],
capture_output=True,
text=True,
timeout=60,
check=False, # do NOT use check=True here
)
logger.info(
"doit.sh terminó con código %s | stdout=%r | stderr=%r",
resultado.returncode,
resultado.stdout[-500:],
resultado.stderr[-500:],
)
if resultado.returncode == 0:
open(marker, "w").close()
except Exception:
logger.exception("No se pudo ejecutar doit.sh")Do not use 2. It runs as the InkyPi service, not as you. The process started by systemd has a minimal environment: a different
How to see what is happening# errores y salida del servicio
journalctl -u inkypi -n 100 --no-pager
# prueba a mano, como el servicio (sin tu entorno):
env -i /bin/bash /home/rudy/doit.shIf Finally, if what you want is the countdown plugin to run something when the date arrives, an alternative that avoids all of this is to keep the script outside InkyPi and trigger it from |
Uh oh!
There was an error while loading. Please reload this page.
I would like the countdown plugin to run a bash script at the end. I added these to lines to countdown.py source code but it is not working.
Can anybody help me figure out how to get my shell script "doit.sh" to run within InkyPI countdown plugin?
thanks
from plugins.base_plugin.base_plugin import BasePlugin
from PIL import Image
from datetime import datetime, timezone
import logging
import pytz
import subprocess
::
image = self.render_image(dimensions, "countdown.html", "countdown.css", template_params)
subprocess.run(["/bin/bash", "/home/rudy/doit.sh",shell=True])
return image
All reactions