Thinstation / thinstation

A framework for making thin and light Linux based images for x86 based machines and thinclients.
https://www.thinstation.net/
810 stars 187 forks source link

run python / xrandr in window not as cronjob #856

Closed rohrbachger closed 1 week ago

rohrbachger commented 2 weeks ago

As we have some thinstations running I would like to get the serial number and model from the screens, and write that to an inventory database. We have about 100 thinstations with dual screen. ( View Horizon)

With python pedid this is no big deal, doing it from terminal.

But I did not figured out to run in the scheduled task or service. Technical I did but with a test I figured out that xrandr did not create output if i is running as a crontab job. It has only to run once per day or restart. Any suggestions and ideas? In pedid the xrandr output is parsed.

Doncuppjr commented 2 weeks ago

Perhaps as a cronjob, the DISPLAY variable is not available.

You could make a script, create a service file and a timer file for that service.

  1. Creating the Service File Create a systemd service file (example.service) that specifies what command or script you want to run. Here’s a basic template:

[Unit] Description=Daily Task Service

[Service] Type=oneshot ExecStart=/path/to/your/script.sh

[Install] WantedBy=multi-user.target

Replace /path/to/your/script.sh with the path to your script or command.

  1. Creating the Timer File Next, create a systemd timer file (example.timer) to schedule the service. Here’s how you can set it up to run once a day:

[Unit] Description=Runs the Daily Task Service once a day

[Timer] OnCalendar=daily Persistent=true

[Install] WantedBy=timers.target

This timer activates the service once a day at midnight. The Persistent=true option ensures that the task will be executed once the system is up if it was down at the scheduled time.

  1. Finally, in some finalize script, you will want to enable the timer.

systemctl enable example.timer

rohrbachger commented 1 week ago

I did it already before like you wrote. The final trick was to export the DISPLAY var. It's working fine now.