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
248 views 7 comments
by anonymous
In view of RUTX50 only having a single modem, I want to have a timed script to switch Sim 1 over to Sim 2 every 8 hours, then back again 8 hours later and so on... (ie three times every 24 hours) It's kind of a way to load balance the data over 2 sources Sim 1 & 2, throughout a day and a week etc.
ie 1 to 2, then 2 to 1, then 1 to 2, then 2 to 1.... a toggle every 8 hours.
Can you provide the script to carry this out?

Thanks

DC

1 Answer

0 votes
by anonymous
Hi, (hopefully) I found the answer after a search.

0 5,13,21 * * * sim_switch change

(at 5am, 13hrs and 21hrs daily)
Best answer
by anonymous
Also, network providers frown at the use of devices other than tablets, phones and tethered devices and have fair use policies so this switching would give the impression of devices being 'turned off periodically.
by anonymous

Hello,

Have you tested the sim_switch command?

I would recommend using the following commands:

To change the SIM:

  • ubus call sim change

To check the current sim:

  • ubus call sim get

For consistency purposes, I would also change the default SIM card in the configuration. So the script would look something like this:

#!/bin/sh

SIM1='1'

SIM2='0'

# Check if SIM1 is currently the primary SIM

IS_SIM1=$(uci get simcard.@sim[0].primary)

if [ "$IS_SIM1" = "$SIM1" ]; then

  # SIM1 is currently primary, switch to SIM2

  uci set simcard.@sim[0].primary="$SIM2"

  uci set simcard.@sim[1].primary="$SIM1"

else

  # SIM2 is currently primary, switch to SIM1

  uci set simcard.@sim[0].primary="$SIM1"

  uci set simcard.@sim[1].primary="$SIM2"

fi

uci commit

logger 'SIM swap triggered.'

ubus call sim change

/etc/init.d/mobifd reload

Crontab can be changed as needed.

0 */8 * * * /etc/sim_swap.sh

Kind Regards,

Andzej

by anonymous

Hi Andzej,

Apologies but I am so rusty at Unix (1987) so long ago!

Crontab entry didn't work fully, sim 1 switch to sim 2 but did not switch back.

How to process/edit/implement your suggestions below?

 #!/bin/sh

SIM1='1'

SIM2='0'

# Check if SIM1 is currently the primary SIM

IS_SIM1=$(uci get simcard.@sim[0].primary)

if [ "$IS_SIM1" = "$SIM1" ]; then

  # SIM1 is currently primary, switch to SIM2

  uci set simcard.@sim[0].primary="$SIM2"

  uci set simcard.@sim[1].primary="$SIM1"

else

  # SIM2 is currently primary, switch to SIM1

  uci set simcard.@sim[0].primary="$SIM1"

  uci set simcard.@sim[1].primary="$SIM2"

fi

uci commit

logger 'SIM swap triggered.'

ubus call sim change

/etc/init.d/mobifd reload

by anonymous

Hi,

Apologies for the late reply.

It looks like the script works fine on my side and switches back and forth. Anyways, could you try a simpler alternative and just use the command 'ubus call sim change'? This command should work fine with the Crontab as well. 

If you encounter any issues with this command, please, let me know!

Kind Regards,

Andzej

by anonymous

Hi Andzej,

I can use the ubus call sim change command

but since I have not used Linux/Unix CLI since 1999 I have forgotten all that I learned.

So how to run the script that you posted.

I copied and pasted it straight in the command prompt and is went through it.

But there is a smoother way. 

Can you explain and perhaps it will remind me of how I should call it.

Many Thanks

Mel

by anonymous

Hello,

Connect to the device via CLI/SSH and execute the following command:

  • crontab -e

You will open crontab in a text editor. Press 'i' to start editing. Use arrows on your keyboard to navigate. Enter the following on a new line (note the spaces between asterisks '*'):

  • * */8 * * * ubus call sim change 2>&1

Save the changes by pressing  'esc' button, typing ':wq' and pressing 'enter'

Crontab information is available here.

Kind Regards,

Andzej

by anonymous
Hi,

Everything works well now with crontab firing at the desired times and the sims toggling.

However, crontab triggers at midnight which was not in my schedule. I only noticed this when I created a log from crontab output.

Q. does Crontab fire at midnight by default?

Update. A factory reboot sorted this out and crontab behaves itself now.