Join two scripts

I have 2 scripts and they work very well, but I have realized that I can make a single script to do both jobs, but I don’t know how to do it, these are the two scripts:

: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   DATE: $[:pick $data 4 6]-$($arrMonths->[:pick $data 0 3])-$[:pick $data 7 11]"
}
/file
:if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filenameIP "flash/$filenameIP"}
: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\n************************************************************\r\nNEW IP: $newIP\t$now\r\n$filecontent"
    set $filenameIP contents=$newfilecontent
    :set currentIP $newIP;
}



:global currentIP
:local newIP [/ip address get [find interface="ETHERT 1"] address]
:set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
:if ($currentIP != $newIP) do={
    /tool e-mail send to="XXXXXXX@hotmail.com" subject=[/system identity get name] start-tls=yes \
        body=" THIS IS THE NEW IP:  $newIP"
    set currentIP $newIP
}

Thanks for your help friends.




EL DONCITO.

really you need help to copy-and-paste two “e-mail” lines from second script on same place to first script?

Thanks for responding friend, I need a single script to send me the new IP address to my email and at the same time register the new IP in the file.txt. You understand me?.




EL DONCITO.

simply copy & paste

    /tool e-mail send to="XXXXXXX@hotmail.com" subject=[/system identity get name] start-tls=yes \
        body=" THIS IS THE NEW IP:  $newIP"

before :set currentIP $newIP;

Thanks for your answer friend REXTENDED, but I just realized that if I have both scripts running at the same time, the one that sends the new IP to the mail does work and the one that registers the new IP in the file.txt does not work, what will happen there?.





EL DONCITO.

because both use same :global variable currentIP

:global currentIP

and the script can not check if the IP is changed, if the variable is :local.

I don’t understand, do you mean that the same global variable currentIP cannot be held by both scripts? and that one of the 2 scripts must have a global variable such as :global storedIP





EL DONCITO.

REXTENDED, how would you solve that?







EL DONCITO.

you can change all the occurencies of the variable name on one of the two script

ok, what if the local variable newIP is placed instead as :global newIP?





EL DONCITO.

As I have already told you another time, I am not answering assumptions.
Obviously, the more variables become global, the more scripts interact with each other.

It 's the case that you study at least a little, on basic things I can not be a teacher.

But if some users want to do it, PLEASE