Hi All,
So, I’m way out of my depth here… I have some scripts that have been mashed together from info on the forum, but I want to combine them into a single one.
Basically what i need to do is the following:
Check if the main WAN connection has connectivity
- If UP, then:
- Make sure Backup4G interface is disabled (if not, then disable)
- Make sure VPN interface is enabled
- Log info Primary UP
- If DOWN, then:
- Log info Primary DOWN
- Check the backup connection’s quota limit (8GB)
- If over 8GB, make sure Backup4G interface is disabled (if not, then disable)
2. If under 8GB then: - Make sure VPN Interface is disabled (if not, then disable)
2. Make sure Backup4G interface is enabled (if not, then enable)
rinse and repeat every 5 minutes
So far, these are the scripts I have:
Code to detect quota
:local traffic ([/file get counter.txt contents] / 1000 / 1000 / 1000)
#set the LTE quota in GB
:local limit 8
:local percent ($traffic*100 / $limit)
:if ($percent >= 90) do={/interface disable Backup4G}
Code to detect if primary WAN interface is UP
:if ([/ping 208.67.222.222 count=5] = 0) do={
:log info "Primary Appears Down"
/if ([interface get "PIA VPN" running] = true) do={interface disable "PIA VPN"}
/if ([interface get "Backup4G" running] = false) do={interface enable "Backup4G"}
} else={
:log info "Primary Appears Up"
/if ([interface get "Backup4G" running] = true) do={interface disable "Backup4G"}
/if ([interface get "PIA VPN" running] = false) do={interface enable "PIA VPN"}
}
Code to get traffic stats for quota
:local counter [/interface get "Backup4G" rx-byte]
:set $counter ($counter + [/interface get "Backup4G" tx-byte])
:local traffic
:if ([:len [/file find where name=counter.txt]] < 1 ) do={
/file print file=counter.txt where name=counter.txt;
/delay delay-time=2;
/file set counter.txt contents="0";
};
:local before value=[/file get counter.txt contents]
:if ($counter > $before) do={
/file set counter.txt contents=$counter
} else= {
:set $traffic ($counter+$before)
/file set counter.txt contents=$traffic
};
The above scripts are what I want to combine into a single workflow… If possible..
I have tried with multiple versions of “if” statements, but the syntax errors always get me.. and for some of them, I really don’t understand how they work (as I copy/pasta from the forum)..
Code for detecting the 4th of the month - (This runs once a day @ 1am, time synced with NTP)
if ([:pick [/system clock get date] ([:find [/system clock get date] "/" ] + 1) 6 ] = "04") do={/file set counter.txt contents="0"}
Any help would be appreciated… Thank you