Community discussions

MikroTik App
 
User avatar
nabilx
just joined
Topic Author
Posts: 23
Joined: Thu Jul 06, 2017 11:19 pm
Location: Syria, Hama
Contact:

I need to convert Content imported from file.txt to a number value  [SOLVED]

Fri Mar 26, 2021 1:40 pm

Hello ,
I'm using snmp-walk to get a value from oid and save it to files as text file
then the script I'm using to extract the value is:
:global content [/file get [/file find name=out.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line "";
:global lastEnd 0;

:do {
  :set lineEnd [:find $content "\n" $lastEnd ] ;
  :set line [:pick $content $lastEnd $lineEnd ] ;
  :set lastEnd ( $lineEnd +2 ) ; 


  :global entry [:pick $line 0 $lineEnd ]
  
} while ($lastEnd < ( $contentLen -2 ) )

:global raw [:pick $line 47 51 ] 

:log info message=$raw

It works fine and desplay for example the number " 195 "
My problem is I need to multiply the output value and devide it etc...
I used this
:global cap [:put ($raw *2) ]

:log info message=$cap
But the outputbecomes in time format " 00:06:30 "
How can I convert the $raw var to a number that can be multiplied?
I'm not expert in scripting .
Thanks
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7042
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: I need to convert Content imported from file.txt to a number value

Fri Mar 26, 2021 1:49 pm

if that is considered time, then [:totime $cap]
 
User avatar
nabilx
just joined
Topic Author
Posts: 23
Joined: Thu Jul 06, 2017 11:19 pm
Location: Syria, Hama
Contact:

Re: I need to convert Content imported from file.txt to a number value

Fri Mar 26, 2021 2:01 pm

Can you please explain more
If you thought i need a time output no, I need the value to remain a normal number
It's converting it to a time format after i use :put ( $raw * 2 ) that's the problem here
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: I need to convert Content imported from file.txt to a number value

Fri Mar 26, 2021 2:14 pm

Not an answer to your question, but if your variable are to be used in this script only, change form global to local
And your do not need the ; after each line. Only when there are multiple command at same line.
 
User avatar
nabilx
just joined
Topic Author
Posts: 23
Joined: Thu Jul 06, 2017 11:19 pm
Location: Syria, Hama
Contact:

Re: I need to convert Content imported from file.txt to a number value

Fri Mar 26, 2021 2:38 pm

Not an answer to your question, but if your variable are to be used in this script only, change form global to local
And your do not need the ; after each line. Only when there are multiple command at same line.
First I need to thank you very much your recent discussion on the forum helped me alot to reach that script above to use snmp to comunicate with my devices
as for the problem in my post it was my mistake to pick 4 lines instead of 3 i managed to solve it thanks alot

Who is online

Users browsing this forum: No registered users and 14 guests