Dynamic Remote Tunnel IP - Command Scripting / Task Scheduler

Hello,

i have a Script wich should Update the Remote IP of a Tunnel Interface every Minute, if the IP of the Remote Site Changes. The Script gets the IP of the Remote Site via DNS.

If i run the Script manually it works fine, but if the Task Scheduler Starts it the IP doesn´t get Updated.

I put a mkdir in the script and the folder was created via the Task Scheduler. So the Script seems to run, but i dont understand why the IP wasn´t updated.

Script:

#!/bin/vbash

mkdir /home/vyos/test
source /opt/vyatta/etc/functions/script-template

newIP=$(getent hosts ipv6.mydnsname.cake | awk '{ print $1 }')
oldIP=$(show interfaces tunnel tun0 remote | awk '{ print $2 }')

echo $newIP
echo $oldIP

if [ $newIP != $oldIP ]
then
        configure
        set interfaces tunnel tun0 remote $newIP
        commit
        save
fi

Task Scheduler Configuration:

vyos@IX# show system task-scheduler
 task updateTunnelIP {
     executable {
         path /home/vyos/updateTunnelIP.sh
     }
     interval 1m
 }

Could you add these lines in your script, before “source” line:

if [ "$(id -g -n)" != 'vyattacfg' ] ; then
    exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
fi

Reference: Executing Configuration Scripts

I Added the Line to the Script. It still works when I run it manuelly, but still not when the Task Scheduler starts ist.

vyos@IX:~$ cat updateTunnelIP.sh
#!/bin/vbash
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
    exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
fi
source /opt/vyatta/etc/functions/script-template

newIP=$(getent hosts ipv6.nix.aa | awk '{ print $1 }')
oldIP=$(show interfaces tunnel tun0 remote | awk '{ print $2 }')

echo $newIP
echo $oldIP

if [ $newIP != $oldIP ]
then
        configure
        set interfaces tunnel tun0 remote $newIP
        commit
        save
fi

Check logs:
sudo journalctl | tee