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
1,101 views 12 comments
by anonymous
Dear support. I need my own script automatically start up I put the script line in the rc.local but the script doesn't run! The line to start the scrip is sh /bin/test in the rc.local file before exit 0. How to make it run automatically?

1 Answer

–1 vote
by anonymous

Hello,

First of all, check if your created script file has set execution permission. To do that, navigate via ssh to the folder where your script is and execute command:

 ls -l

Your output should look something like that:

  • r - refers to read permission.
  • w - refers to write permission.
  • x - refers to execute permission.

If there are none execute permission set, please use this command:

chmod +x test.sh

Secondly, edit /etc/sysupgrade.conf file to preserve your script after upgrades. For example my script is in root folder:

Do not forget to save changes!

And lastly, check if you have specified correct script file path in /etc/rc.local file. My file is in root folder so it looks like this:

Regards.

by anonymous

my has -rw-r--r--    1 root     root is it important to have sh extension of the file like in your example test.SH? is it important to have dot ./bin/test in the rc.local?

by anonymous

In test.SH sh extension is not mandatory. Also sh test.sh works exactly same way as ./test.sh

I see your script file does not have execution rights. Please use chmod +x command to allow execution for your file.

by anonymous
I did it. Does't work. Change to 0755 via WinSCP manually
by anonymous
So in rc. local the line is sh /bin/test3. Is it ok?
by anonymous
Do I need to make rc.local also executable?
by anonymous
It should be fine. Just in case you could try out ./bin/test3.

If that does not help, please send me your script via private message. I will check if there is something else wrong.
by anonymous

could try out ./bin/test3 - doesnt work. Work only with sh /bin/test3.

by anonymous

I found the issue in your script.

Your script starts with 

#!/bin/bash 

sleep 5

Change sleep duration to 60 or something longer than 45, because grep function can't find 'Joined LTE network' string until your mobile connection is up. To put it in short, script is executed faster than router connects to network.

Regards.

by anonymous
What about then sim switch and modem restart?! These cause connection to network faster then reboot?
by anonymous
When you specify your script directory in rc.local file, script automatically starts every time system starts. SIM switch and modem restart is another router features and you need to write your script differently. At least we figured out how to start it, now it is up to you to write correct script using ssh. Sadly, Teltonika staff do not write scripts for customers.

Regards.
by
That’s ok. I know that teltonika doesn’t. But for sim switch  and for modem restart what should the beginning? Does my start of script will not work with sim switch and restart the modem?
by anonymous

I suggest to check what strings logread output shows when modem restart and SIM switch events occur and try to use case statement for each scenario. For example:

case word in

   pattern1)
      Statement(s) to be executed if pattern1 matches
      ;;
   pattern2)
      Statement(s) to be executed if pattern2 matches
      ;;
   pattern3)
      Statement(s) to be executed if pattern3 matches
      ;;
   *)
     Default condition to be executed
     ;;