Thinstation / thinstation

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

crontab - starting python script or bash script #601

Closed rohrbachger closed 3 years ago

rohrbachger commented 4 years ago

I have now tested several ways, but cant get it working.

I`m trying to run a script after reboot: @reboot /bin/test.py

or @reboot /bin/python /bin/test.py

But both are not working if started by cron. If I start manually in the terminal window it works.

python script I made +x First line in python script is

!/user/bin/env python

I also tried a bash script:

!/bin/bash

/bin/python /bin/test.py

If I start manual this works fine. Also in general crontab works fine, I do see an entry in messages. Also for my test.sh. But the script did not the job. ntpdate worked fine. @reboot /bin/ntpdate 10.12.220.10

Probably the solution is very easy, but I was not able to find, and spend now some time. Is the problem because of busybox?

Thinstation commented 4 years ago

Could be the process killer. Kind of depends on how you call the script. Put it in the right place, and it will run.

rohrbachger commented 4 years ago

Well, after spending a lot of time I gave up this way. @reboot ntpdate works fine script starting worked somehow, but not correct @reboot /bin/test.sh test script was devinetely started, I wrote a log. But python script was not working.

I ´m using now the service way, this seems to work. Small issue in python, because the timezone is not taken in use. But this should be easy.

the magic with the process killer I did not found, I guess /bin is the right place to run.

Doncuppjr commented 4 years ago

What is it exactly you are trying to do on reboot?

On Thursday, October 8, 2020, 01:12:42 AM PDT, rohrbachger notifications@github.com wrote:

Well, after spending a lot of time I gave up this way. @reboot ntpdate works fine script starting worked somehow, but not correct @reboot /bin/test.sh test script was devinetely started, I wrote a log. But python script was not working.

I ´m using now the service way, this seems to work. Small issue in python, because the timezone is not taken in use. But this should be easy.

the magic with the process killer I did not found, I guess /bin is the right place to run.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe .

rohrbachger commented 4 years ago

well in general I was trying to run a pyhton script after boot. made the python file +x, also changed the first line. But whatever I tried, it did not run. From the terminal it works. So I created a bash script and tried to call the python with /bin/python /bin/test.py Also no success, but I do see the cron job in general is executed. So I have up thi way and created a service entry for this.

But I would like to know why it is not working. I think it is easier to use a crontab job. Where and what is the process killer?

Thinstation commented 4 years ago

If you want to call the script as the running user when the system boots up, call it from .xinitrc. If you want the script to run as root or any other user, then make a init file in /etc/init.d, and create a systemd service file.

rohrbachger commented 3 years ago

fixed, using init.d