Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to a make it work in DSM (Synology) #57

Open
iFredOS opened this issue Aug 24, 2020 · 10 comments
Open

How to a make it work in DSM (Synology) #57

iFredOS opened this issue Aug 24, 2020 · 10 comments

Comments

@iFredOS
Copy link

iFredOS commented Aug 24, 2020

Hi, I found your bash script interesting but I want to use it on my Synology server. It is possible to modify it to make it works or install something for this to happen?

Thank you in advance!

@cleanbrowsing
Copy link
Owner

Not familiar with it. What error do you get there?

@michealespinola
Copy link

It wont work on a Synology NAS by default because it is missing bc and dig. I'm in the same boat, but have been unable to find a compatible copy of bc.

@dcid
Copy link

dcid commented Oct 25, 2022

Is there a tool similar to dig in there at least? What type of shell (and version) is included?

@michealespinola
Copy link

michealespinola commented Oct 25, 2022

dig can be acquired somewhat easily, and should be available on all Synology devices by installing an add-on package that is in the Package Center. The package called "SynoCli Network Tools" from SynoCommunity is the easiest choice and should be installable on any Synology NAS device.

bc on the other hand is pretty much impossible to find. I've been rooting through lots of installable apps/packages and it doesn't come with anything that I can find. It's still an active hunt of mine to find.

The latest Synology DSM (7.1.1) is running GNU bash version 4.4.23(1)-release, on a highly customized/butchered Debian Linux kernel. It's unfortunately not possible to install Debian packages on it. It also does not come with full/standard utility set that you would expect.

I can help you with any insider knowledge and list of tools, as best I can, that are available on a "stock" system. I really appreciate your interest to this issue.

@michealespinola
Copy link

michealespinola commented Oct 25, 2022

Please pardon my ignorance, but if I'm understanding the necessity of bc, it looks like a more universally-generic tools such as awk can handle floating-point arithmetic. Is this correct?

bc is a new tool to me, but I am going to see if I can make modifications to the script utilizing awk instead. It's what I am seeing as the most commonly recommended alternative. It's unfortunate that Synology chose to not make their environment properly POSIX compliant with a full set of standard utilities.

@michealespinola
Copy link

michealespinola commented Oct 30, 2022

Again forgiving my linux ignorance, but I've been diving into this more from the Synology environment perspective (while continuing to try to expand my linux knowledge). The last thing I wanted to do was alter the code- so going back to my initial approach I continued to try to solve the riddle of bc on Synology.

I discovered that older versions of the Synology DSM (the customized version of their Debian OS) actually came with bc, and that there are modern compatibile docker containers for various apps that also come with bc. However, they are not standalone versions - they have all been versions that are an embedded component of a toolset called "BusyBox".

BusyBox is actually an easy drop-in binary on Synology. However, because its an embedded app, you have to create a link in your PATH from bc -> "busybox bc" in order to make it seamless in your environment.

That said, I think that awk would still be the easiest solution for hobbyists encountering scripts like this. I think that issues like this will only become more so as more laymen are exposed to home NAS devices, automation devices, etc. bc is certainly a simpler tool to use, but the corresponding awk code doesn't seem complicated or process time expensive, and would make the script more universally usable/adaptive. I'm still going to look into an awk solution and will probably submit a pull request if there is interest.

@michealespinola
Copy link

michealespinola commented Dec 10, 2022

Note/caveat: I would consider myself a bash novice. What I am proposing could very well be stupid.


Looping back to this, I was able to successfully substitute bc with awk, with this:

bc()
{
    awk -v a="$1" -v b="$2" 'BEGIN { printf "%.2f", a/b }' </dev/null
}

Using which or other means, you can check if bc exists in the PATH, and if not activate that function as a replacement. The rest of the code-calls for bc can exist as-is.

That bit done, there were still other modifications that had to be made to get the code to work properly on a Synology:

  1. Even though you can get dig on the system by installing the "SynoCli Network Tools" package, it does not support the options +time, or +stats, so those options had to be removed to run without an associated error. Those options could be checked for and activated dynamically, but I haven't got that far yet.
  2. The NAMESERVERS variable capture had to be altered to get the intended data properly with the same formatting as the PROVIDERS* formatting (surprised others dont see a duplication-type error here?):

NAMESERVERS=$(cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/' | awk '{print $2}')

I also added some code to dynamically resize the first column to compact the information as much as possible. Example output:

time { bash dnstest-fixes.sh; }
Provider      t1   t2   t3   t4   t5   t6   t7   t8   t9      Average
------------- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----------
nameserver1   29   19   34   15   17   18   19   47   17     23.89 ms
nameserver2   47   17   48   32   19   17   18   49   34     31.22 ms
AdGuard       370  84   89   82   83   87   96   87   84    118.00 ms
AlternateDNS  97   82   84   81   82   82   81   82   80     83.44 ms
CleanBrowsing 79   79   79   79   79   79   77   80   79     78.89 ms
Cloudflare    19   19   20   18   19   20   34   18   18     20.56 ms
Comodo        81   79   78   78   81   79   121  162  82     93.44 ms
DNSFilter     18   17   18   15   17   16   18   18   17     17.11 ms
DNS.Watch     171  169  184  1000 161  164  166  167  169   261.22 ms
Freenom       1000 211  224  208  249  335  308  606  211   372.44 ms
Google        20   16   25   16   19   18   19   17   17     18.56 ms
Level3        18   17   18   18   18   16   17   22   14     17.56 ms
Neustar       31   25   28   26   29   26   27   25   30     27.44 ms
NextDNS       17   17   17   15   17   16   16   17   17     16.56 ms
Norton        16   16   18   17   18   25   17   17   20     18.22 ms
OpenDNS       62   17   34   18   17   18   19   75   48     34.22 ms
OpenNIC       122  84   103  82   82   85   96   82   80     90.67 ms
Quad9         30   30   29   29   28   31   36   40   38     32.33 ms
SafeDNS       79   56   57   55   56   62   58   54   98     63.89 ms
UltraDNS      25   25   33   28   24   25   23   23   27     25.89 ms
UncensoredDNS 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000.00 ms
Verisign      19   18   17   16   16   25   18   18   21     18.67 ms
Yandex        179  181  238  183  184  185  188  206  184   192.00 ms

real    0m27.949s
user    0m2.046s
sys     0m1.379s

Note: I set the dig +timout to 1 second, which is why you see some repeated "1000" results. I see no reason to entertain anything that goes past 1 full second.

All that said and done, it can run properly in a Synology DSM environment. Any comments, suggestions, etc are very much welcome.

@michealespinola
Copy link

I've continued to make improvements to how the information is logged and processed, as well as adjustments for broader system compatibility. I invite anyone interested to check out my fork:

https://github.com/michealespinola/syno.dnsperftest

An example of the current output can be found in the README.md

@telnetdoogie
Copy link

Old thread here, but I am running this script on Syno by installing the SynoCli Network Tools (dig etc) and SynoCli Misc Tools (bc etc) and a small modification to the script for checking for nameservers (tab instead of spaces)

@telnetdoogie
Copy link

...modification to script for tabs vs spaces resolved in #86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants