Linux Script File 1 :-
wget -O encap.txt -N /root/encap https://portal.ampr.org/getdata.php?t=encap
/root/encap/process-encap-router.sh > /root/encap/router.raw.txt
ftp -n -i YOUR_ROUTER_EXTERNAL_ADDRESS <<EOF user USERNAME PASSWORD put /root/encap/router.txt encap.rsc quit EOF
**************************************************************************** ************************* Linux Script file 2 (process-encap-router.sh) :-
cat /root/encap/encap.txt | grep "^route" | grep -v " XXX.XXX.XXX.XXX" | \ awk '{ split($3, s, "/") split(s[1], n,".") if (n[1] == "") n[1]="0" if (n[2] == "") n[2]="0" if (n[3] == "") n[3]="0" if (n[4] == "") n[4]="0" if (s[2] == "1") mask="128.0.0.0" else if (s[2] == "2") mask="192.0.0.0" else if (s[2] == "3") mask="224.0.0.0" else if (s[2] == "4") mask="240.0.0.0" else if (s[2] == "5") mask="248.0.0.0" else if (s[2] == "6") mask="252.0.0.0" else if (s[2] == "7") mask="254.0.0.0" else if (s[2] == "8") mask="255.0.0.0" else if (s[2] == "9") mask="255.128.0.0" else if (s[2] == "10") mask="255.192.0.0" else if (s[2] == "11") mask="255.224.0.0" else if (s[2] == "12") mask="255.240.0.0" else if (s[2] == "13") mask="255.248.0.0" else if (s[2] == "14") mask="255.252.0.0" else if (s[2] == "15") mask="255.254.0.0" else if (s[2] == "16") mask="255.255.0.0" else if (s[2] == "17") mask="255.255.128.0" else if (s[2] == "18") mask="255.255.192.0" else if (s[2] == "19") mask="255.255.224.0" else if (s[2] == "20") mask="255.255.240.0" else if (s[2] == "21") mask="255.255.248.0" else if (s[2] == "22") mask="255.255.252.0" else if (s[2] == "23") mask="255.255.254.0" else if (s[2] == "24") mask="255.255.255.0" else if (s[2] == "25") mask="255.255.255.128" else if (s[2] == "26") mask="255.255.255.192" else if (s[2] == "27") mask="255.255.255.224" else if (s[2] == "28") mask="255.255.255.240" else if (s[2] == "29") mask="255.255.255.248" else if (s[2] == "30") mask="255.255.255.252" else if (s[2] == "31") mask="255.255.255.254" else mask="255.255.255.255"
if ($5 == "YOUR_ROUTER_EXTERNAL_ADDRESS") printf ""
else printf "interface ipip add name=ipip-ampr-%s local-address=YOUR_ROUTER_EXTERNAL_ADDRESS remote-address=%s disabled=no\r\nip address add address=YOUR_ROUTER_44_IP interface=ipip-ampr-%s\r\n",$5,$5,$5
}'
cat /root/encap/encap.txt | grep "^route" | grep -v " XXX.XXX.XXX.XXX" | \ awk '{ split($3, s, "/") split(s[1], n,".") if (n[1] == "") n[1]="0" if (n[2] == "") n[2]="0" if (n[3] == "") n[3]="0" if (n[4] == "") n[4]="0" if (s[2] == "1") mask="128.0.0.0" else if (s[2] == "2") mask="192.0.0.0" else if (s[2] == "3") mask="224.0.0.0" else if (s[2] == "4") mask="240.0.0.0" else if (s[2] == "6") mask="252.0.0.0" else if (s[2] == "7") mask="254.0.0.0" else if (s[2] == "8") mask="255.0.0.0" else if (s[2] == "9") mask="255.128.0.0" else if (s[2] == "10") mask="255.192.0.0" else if (s[2] == "11") mask="255.224.0.0" else if (s[2] == "12") mask="255.240.0.0" else if (s[2] == "13") mask="255.248.0.0" else if (s[2] == "14") mask="255.252.0.0" else if (s[2] == "15") mask="255.254.0.0" else if (s[2] == "16") mask="255.255.0.0" else if (s[2] == "17") mask="255.255.128.0" else if (s[2] == "18") mask="255.255.192.0" else if (s[2] == "19") mask="255.255.224.0" else if (s[2] == "20") mask="255.255.240.0" else if (s[2] == "21") mask="255.255.248.0" else if (s[2] == "22") mask="255.255.252.0" else if (s[2] == "23") mask="255.255.254.0" else if (s[2] == "24") mask="255.255.255.0" else if (s[2] == "25") mask="255.255.255.128" else if (s[2] == "26") mask="255.255.255.192" else if (s[2] == "27") mask="255.255.255.224" else if (s[2] == "28") mask="255.255.255.240" else if (s[2] == "29") mask="255.255.255.248" else if (s[2] == "30") mask="255.255.255.252" else if (s[2] == "31") mask="255.255.255.254" else mask="255.255.255.255"
if ($5 == "YOUR_ROUTER_EXTERNAL_ADDRESS") printf ""
else if (s[2] == "") printf "ip route add dst-address=%s.%s.%s.%s gateway=ipip-ampr-%s\r\n",n[1],n[2],n[3],n[4],$5
else printf "ip route add dst-address=%s.%s.%s.%s/%s gateway=ipip-ampr-%s\r\n",n[1],n[2],n[3],n[4],s[2],$5
}'
awk '!x[$0]++' /root/encap/router.raw.txt > /root/encap/router.txt
**************************************************************************** ************************* Router Script file :-
/ip address remove [/ip address find where interface~"ipip-ampr-"] ; ;delay 3s ; /ip address remove [/ip address find where interface~"unknown"] ; ;delay 3s ; /ip route remove [/ip route find where gateway~"ipip-ampr-"] ; ;delay 3s ; /interface ipip remove [/interface ipip find where name~"ipip-ampr-"] ; ;delay 3s ; /ip route remove [/ip route find where gateway~"unknown"] ; ;delay 3s ; /import encap.rsc
Best Regards, Hugh Golding TEQ Systems Limited
T +44 7841 749345 + hugh@teqsys.co.uk
-----Original Message----- From: 44net-bounces+hugh=teqsys.net@hamradio.ucsd.edu [mailto:44net-bounces+hugh=teqsys.net@hamradio.ucsd.edu] On Behalf Of Hugh Golding Sent: 23 August 2013 09:31 To: 'AMPRNet working group' Subject: Re: [44net] Something simple
(Please trim inclusions from previous messages) _______________________________________________ I have a simpler mikrotik script working. It isn't pretty but it updates the router every day.
If your interested I can explain it.
My linux box downloads encap.txt from ftp site and processes it every night. It then uploads a txt file with the commands in it to the router by ftp.
A simple script on the mickrotik the runs the commands within.
It works but isn't technical.
Best Regards, Hugh Golding TEQ Systems Limited
T +44 7841 749345 + hugh@teqsys.co.uk
-----Original Message----- From: 44net-bounces+hugh=teqsys.net@hamradio.ucsd.edu [mailto:44net-bounces+hugh=teqsys.net@hamradio.ucsd.edu] On Behalf Of YT9TP Pedja Sent: 23 August 2013 09:20 To: AMPRNet working group Subject: Re: [44net] Something simple
(Please trim inclusions from previous messages) _______________________________________________ On 23.8.2013 0:55, Tom Hayward wrote:
What encap file did you test with? I thought Mikrotik had a 4KB limit for reading text files.
I used encap.txt trimmed to just few lines to easy debugging.
I did not realize there is such a limit. DOH! That makes my script unusable.
Well, at least I tried and I got proof of concept :)
Now, I will have to use another approach.
Pedja YT9TP
_________________________________________ 44Net mailing list 44Net@hamradio.ucsd.edu http://hamradio.ucsd.edu/mailman/listinfo/44net http://www.ampr.org/donate.html
_________________________________________ 44Net mailing list 44Net@hamradio.ucsd.edu http://hamradio.ucsd.edu/mailman/listinfo/44net http://www.ampr.org/donate.html