Script Output Works Manually But Not Automatically?

Hi everyone

I have a bit of a problem with a script on a router (RB750G running ROS 6.18).

Below is the script. Basically what it does is pull the TX and RX bytes from a specific interface every hour, convert the data to MB, and then append it to a text file named after each specific date.

{
  # global variables
  :global thisdate [/system clock get date]
  :global thistime [/system clock get time]
  :global datetimestring ([:pick $thisdate 0 3]."-".[:pick $thisdate 4 6] )

  # check if file exists, if not create it and set contents to nothing
  :if ([:len [/file find name="$datetimestring.txt"]] != 1) do={
    /file print file=$datetimestring
    :delay 2s;
    /file set $datetimestring contents="";
  }

  # set variables
  :global fileContent;
  :global thisHour [:pick $thistime 0 8]
  :global txdata [/interface get 5 tx-byte];
  :global rxdata [/interface get 5 rx-byte];

  # convert to MB
  :set txdata (($txdata / 1048576) . " MB")
  :set rxdata (($rxdata / 1048576) . " MB")

  # get file content
  :set fileContent [/file get $datetimestring content];

  # append signal to fileContent
  :set fileContent ($fileContent . $thisHour . "\tTX: " . $txdata . "\tRX: " . $rxdata);

  # re-write file content
  /file set $datetimestring contents=($fileContent . "\r\n");
}

The output of the script is something like this:

09:57:31	TX: 0 MB	RX: 451 MB
09:59:02	TX: 0 MB	RX: 451 MB

Now when running the script manually it works without any problems, but when I set up a scheduler to run the script every hour (via the command /system script run ) it produces only the following output:

08:00:00 TX: MB RX: MB
09:00:00 TX: MB RX: MB

For some reason it does not insert the variables.

I’ve checked the script multiple times but cannot seem to find a fault. Any help would be much appreciated.

Thank you

script doesnt work in 6.19

You can not use item numbers in scripts (i.e. get 5). If the interface you want to monitor is called ‘thisOne’ you should change this:

:global txdata [/interface get [find name="thsisOne"] tx-byte];
:global rxdata [/interface get [find name="thsisOne"] rx-byte];

Unless this script is part of a greater script complex, then there is no reason to use :global, :local should be sufficient.

Thank you very much! This solved my problem