Community discussions

MikroTik App
 
O1DMBFan
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Fri Dec 05, 2008 11:08 pm

Netwatch/Script Cannot Create File

Thu Aug 23, 2018 3:57 am

Hello,
I understand that Netwatch has been depreciated in 6.42 and am altering our scripts and netwatch procedures to support the limited permissions.

The problem I'm running into is neither Netwatch or a Scheduler is able to run the following command:
/file print file="file.txt"

The code/script halts at that line and doesn't proceed. The script has policy rights to read, write, reboot, and test. When running this script from a terminal there is no problem and it succeeds. Anyone else having this issue?

Thanks.
 
orsib
just joined
Posts: 7
Joined: Wed Jan 31, 2018 11:57 am

Re: Netwatch/Script Cannot Create File

Thu Aug 23, 2018 4:47 pm

Hello.

I just experienced the same problem.
Could we use global variable instead?
I would like to monitor my internet connection and log when the connection was lost and when it is back. Also I would like to send this information via email to my email address when the connection is back. My idea was that when the connection is down I write a timestamp to a file and when the connection is back I will send an email with the stored timestamp and the actual time and date. Using this method I can engage my ISP to fix my connection issues as I will be able to precisely tell them when my connection was lost and how long.
Any idea how I can acheive this if netwach cannot create/write file?

Regards,
Balazs
 
O1DMBFan
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Fri Dec 05, 2008 11:08 pm

Re: Netwatch/Script Cannot Create File

Thu Aug 23, 2018 4:56 pm

Hello.

I just experienced the same problem.
Could we use global variable instead?
I would like to monitor my internet connection and log when the connection was lost and when it is back. Also I would like to send this information via email to my email address when the connection is back. My idea was that when the connection is down I write a timestamp to a file and when the connection is back I will send an email with the stored timestamp and the actual time and date. Using this method I can engage my ISP to fix my connection issues as I will be able to precisely tell them when my connection was lost and how long.
Any idea how I can acheive this if netwach cannot create/write file?

Regards,
Balazs
Hey Orsib,
Thanks for getting involved. I know that permissions are still there to allow the editing of an already created file. Maybe you can create the file as a logged in user with full rights then have your script just clear the contents of this file and write new contents each instance of an outage. What do ya think?

Cheers,
 
orsib
just joined
Posts: 7
Joined: Wed Jan 31, 2018 11:57 am

Re: Netwatch/Script Cannot Create File

Wed Aug 29, 2018 2:57 pm

Hello.

I just experienced the same problem.
Could we use global variable instead?
I would like to monitor my internet connection and log when the connection was lost and when it is back. Also I would like to send this information via email to my email address when the connection is back. My idea was that when the connection is down I write a timestamp to a file and when the connection is back I will send an email with the stored timestamp and the actual time and date. Using this method I can engage my ISP to fix my connection issues as I will be able to precisely tell them when my connection was lost and how long.
Any idea how I can acheive this if netwach cannot create/write file?

Regards,
Balazs
Hey Orsib,
Thanks for getting involved. I know that permissions are still there to allow the editing of an already created file. Maybe you can create the file as a logged in user with full rights then have your script just clear the contents of this file and write new contents each instance of an outage. What do ya think?

Cheers,
Hello.
Unfortunately this is not resolving anything as I am only using the admin user and there are no other users specified.
Regards,
Balazs
 
O1DMBFan
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Fri Dec 05, 2008 11:08 pm

Re: Netwatch/Script Cannot Create File

Wed Aug 29, 2018 4:13 pm

Hello.
Unfortunately this is not resolving anything as I am only using the admin user and there are no other users specified.
Regards,
Balazs
For my proposed solution you would not need to have any other users. Since the issue is with the "creation" of a file I suggest creating it yourself, manually.

1. Log into device as admin
2. Create the file you'd like.
3. Program script to "edit" the file. (Instead of the script "creating" the file)

Does that make sense?
 
orsib
just joined
Posts: 7
Joined: Wed Jan 31, 2018 11:57 am

Re: Netwatch/Script Cannot Create File

Wed Aug 29, 2018 4:41 pm

Hello.
Unfortunately this is not resolving anything as I am only using the admin user and there are no other users specified.
Regards,
Balazs
For my proposed solution you would not need to have any other users. Since the issue is with the "creation" of a file I suggest creating it yourself, manually.

1. Log into device as admin
2. Create the file you'd like.
3. Program script to "edit" the file. (Instead of the script "creating" the file)

Does that make sense?
Could you please let me know which commands I should use to cleanup the file, read from the file and write into the file I created manually as per your instructions below?

Here is my script so far:

ON UP:
:log warning "Internet Up"
:local time;
:local date;
:local lost [/file get internetconnection.txt contents];
:set date [/system clock get date];
:set time [/system clock get time];
/tool e-mail send to=xxx.xxx@gmail.com subject="[BUDAPEST] Internet Connection Report" body="Connection is lost at $lost. Connection is back at $time $date" start-tls=yes;
ON DOWN:
:log warning "Internet Down"
/file print file=internetconnection.txt;
:delay 2;
/file set internetconnection.txt contents=("$[/system clock get time]" . " " . "$[/system clock get date]");
I created the blank file using the following command (after ssh'd to the box using putty):
/file print file=internetconnection.txt;
 
orsib
just joined
Posts: 7
Joined: Wed Jan 31, 2018 11:57 am

Re: Netwatch/Script Cannot Create File

Mon Sep 03, 2018 6:24 pm

Any idea how I could resolve this problem?
 
orsib
just joined
Posts: 7
Joined: Wed Jan 31, 2018 11:57 am

Re: Netwatch/Script Cannot Create File

Tue Sep 11, 2018 1:21 pm

Any idea how I could resolve this problem?
It seems it is resolved since I upgraded to 6.43

Who is online

Users browsing this forum: No registered users and 43 guests