gclayburg / synology-diskstation-scripts

Update Synology DNS records from DHCP IP address reservation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

incorrect syntax if-condition S99pollDHCP.sh, line 42

Valenorious opened this issue · comments

When I tried to execute the S99pollDHCP.sh script to stop it from the commandline I got back:

root@Synna:/usr/local/etc/rc.d# ./S99pollDHCP.sh stop
./S99pollDHCP.sh: line 42: [: : integer expression expected

Looking at that line it seems the text quotation marks are improperly placed. (But I'm a noob at linux scripting) Correcting the conditional statement as follows made it work:
if [ "$MYPID -gt 1" ]; then

I tried also as followed (akin to line 29)
if [ $MYPID -gt "1" ]; then
but this results in error:

root@Synna:/usr/local/etc/rc.d# ./S99pollDHCP.sh stop
./S99pollDHCP.sh: line 42: [: -gt: unary operator expected

Oddly enough this line 29 executes normally when starting the script with:

root@Synna:/usr/local/etc/rc.d# ./S99pollDHCP.sh start
2017-02-21_18:12:35 - is poll-dhcp-changes.sh running?
2017-02-21_18:12:35 - starting poll-dhcp-changes

I'm still a noob when it comes to github and linux scripting so I didn't want to try and make a fork or whatever is needed to make a change in the code. Please verify if this is correct, and not break some other consideration.

Also, I noticed this script only works for the default case of a administrative user "admin". For security reasons I disabled that user and made a custom administrator user. Can these scripts be made more flexible in this regard? Or was there some reason to not deviate from default?

Hi - it looks like the first error you reported (line 42) happened for you because you ran "S99pollDHCP.sh stop" when poll-dhcp-changes was not running. The script should probably be fixed to deal with this situation better.

You are correct about the permissions issue. These scripts assume everything is run as root. This is because the script needs to modify DNS files that the DNS service also reads and writes to, and it runs as root. It might be possible to modify how these services work, but it would probably involve changing how DNS and DHCP services work in synology? If this is something you'd like to do, I'll take a look at a pull request

Actually I looked into this a little more it might have been due to multiple poll-dhcp-changes.sh processes running. I fixed the script to deal with this better. This is what I get for output when I run this manually:

DiskStation> ./S99pollDHCP.sh status
2017-02-22_09:34:48 - poll-dhcp-changes is running:
21465 root      3768 S    /bin/sh /var/services/homes/admin/poll-dhcp-changes.sh
DiskStation> 
DiskStation> ./S99pollDHCP.sh stop
2017-02-22_09:34:59 - killing PID: 21465
DiskStation> 
DiskStation> ./S99pollDHCP.sh start
2017-02-22_09:35:03 - is poll-dhcp-changes.sh running?
2017-02-22_09:35:03 - starting poll-dhcp-changes
DiskStation> 
DiskStation> pwd
/usr/local/etc/rc.d