Hi guys, can you help me with a script that writes a message recorded in the routerboard log to a .txt file. I would like to record in the file. txt every time I change my IP address which is dynamic Thanks for your help
EL DONCITO.
Depending on what your trying to do, you may not need a script. the System>Logging>Action lets you create a "custom log action" for "disk" where you can pick file name, length, etc. Then in the System>Logging>Rules you can add something for the "dhcp,info" topics. Like so:Hi guys, can you help me with a script that writes a message recorded in the routerboard log to a .txt file. I would like to record in the file. txt every time I change my IP address which is dynamic Thanks for your help
/system logging action
add disk-file-count=1 disk-file-name=flash/ipchg name=ipchg target=disk
/system logging
add action=ipchg topics=dhcp,info
This parameter is available in v6.39rc33+ These are available variables that are accessible for the event script:
bound - 1 - lease is added/changed; 0 - lease is removed
server-address - server address
lease-address - lease address provided by server
interface - name of interface on which client is configured
gateway-address - gateway address provided by server
vendor-specific - stores value of option 43 received from DHCP server
lease-options - array of received options
:global actualIP;
:local newIP [/ip address get [find interface="ether1"] address];
:if ($newIP != $actualIP) do={
:put "ip address $actualIP changed to $newIP";
:set actualIP $newIP;
/system script run THIS-RUNS-WHEN-THE-IP-CHANGES;
}
This is the 'checkIP' script that I use, scheduled to run every 5 minutes.
Then make the second script do whatever you want, when the IP has changed..Code: Select all:global actualIP; :local newIP [/ip address get [find interface="ether1"] address]; :if ($newIP != $actualIP) do={ :put "ip address $actualIP changed to $newIP"; :set actualIP $newIP; /system script run THIS-RUNS-WHEN-THE-IP-CHANGES; }
:global filenameIP "iphistory.txt"
:global arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
{
:local data [/system clock get date]
:local itime [/system clock get time]
:local hours [:pick $itime 0 2]
:local minsec [:pick $itime 2 8]
:local mhours [:tonum $hours]
:local msymbl "AM"
:if ($mhours > 11) do={:set msymbl "PM"}
:set mhours ($mhours % 12)
:if ($mhours = 0) do={:set mhours 12}
:if ($mhours < 10) do={:set mhours "0$mhours"}
:local mtime "$mhours$minsec $msymbl"
:global now "TIME:$mtime HORA: $[:pick $data 4 6]-$($arrMonths->[:pick $data 0 3])-$[:pick $data 7 11]"
}
/file
:if ([:len [find where name=$filenameIP]] = 0) do={print file="$filenameIP"; :delay 5s; set $filenameIP contents=""}
:global currentIP
:local newIP [/ip address get [find interface="ETHERT 1"] address]
:set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
:if ($newIP != $currentIP) do={
/file
:delay 5s
:local filecontent [get $filenameIP contents]
:local newfilecontent "********************************************************************\r\nNEW IP: $newIP\t$now\r\n$filecontent"
set $filenameIP contents=$newfilecontent
:set currentIP $newIP
}