FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
241 views 4 comments
by anonymous
Hi,

I want to start a python script after the boot process of my RUTX12 which shall run for the rest of the boot cycle. Therefore the script contains a while(true) statement.

First thing I tried was to add a call to my python script to the userscript section in the WebUI. This did not work, propably because the process gets killed automatically when it takes to long. I can not verify this, but I did not work. So I tried to create a bash file which executes the python script in the background (&) but this did not work as well.

So my next step was to look at alternatives. I stumbled upon crontab. So I added a line which creates a new cronjob which sleeps for 60 seconds and then executes the python script in the background. I get a parsing error, as if the @reboot option is not available in crontab or as if I misformatted something.

Error Msg:

cron.err crond[*PID*]: user root: parse error at @reboot
cron.err crond[*PID*]: user root: parse error at /etc/startupscript.sh
cron.err crond[*PID*]: user root: parse error at >
cron.err crond[*PID*]: user root: parse error at /tmp/log/mylog.log
cron.err crond[*PID*]: user root: parse error at 2>&1

How could I run the script after the RUTX12 is booted?

1 Answer

0 votes
by anonymous

Hello,

  

Services that run continuously should not be used, as they will most likely cause issues with other services. So the best approach here would indeed be to use Crontab. The Crontab service can only work with pre-defined syntax. I'd recommend using a Crontab Generator to generate a correct string. For your example, to run the script every minute, syntax like this needs to be used:

* * * * * /etc/startupscript.sh > /tmp/log/mylog.log

It will start running automatically after the device is booted, so there is no need to run any service separately.

Hope this helped!

  

Best regards,
DaumantasG

by anonymous
Thank you for your answer! If one of the processes created by crontab is still running, would another process be instantiated or would it be skipped?
by anonymous
Crontab is intented to be used with scripts, that execute a task and the exit. For example, if you'd like to collect some data every 10 minutes and send it to a remote server. Crontab will simply execute this script every 10 minutes.

If the last cron job has not finished running, crontab will run it again, creating a second instance of that script or crashing the first one (depending on the script).

Perhaps you could commendpt more about your use-case to see if we could find the best option?

  

Best regards,

DaumantasG
by anonymous
Hello DaumantasG,

I want to to execute a python script which runs as long as the router is powered on. My solution for now is, that I execute a bash script which checks if my python script is already running and if not it starts a process. If it is already running, my bash script ends without starting the python process.

Maybe a service would be a solution, do you have experience setting one up?

Best regards,

Steffen
by anonymous

Hello,

  

In this case, you could try to set up your Python script as an init.d script. Instructions on how to achieve this can be found in OpenWRT Wiki here. I'd recommend using the START=99 argument to avoid delaying any system scripts from starting up. In the start() function simply specify your Python script.

  

Best regards,
DaumantasG