Script in Cron executed, but has no effect

OS type and version: ubuntu 20.04
Webmin version: 1.984
Virtualmin version: 6.17

On Hetzner-Cloud there is a known issue, that a server lost it’s ipv4 address, because the server doesn’t refresh the ip in the right way.
To fix this, I have created a small bash-script which should run every minute to check if ipv4 is available, if not the script should fetch it via dhcpclient eth0

If I do execute this script as root in cli, it works as expected. But if I put it into Webmin’s cronjobs (or in crontab -e from root), it doesn’t work.

# Checks if the IPv4 address is set on the given network interface
ipString="inet "
result=`/usr/sbin/ifconfig $interface | /usr/bin/grep "$ipString"`
if [[ -z $result ]];
 /usr/sbin/dhclient $interface
 `/usr/local/bin/discord_notification SERVER 58 "IPv4 - reconnect (dhclient eth0) "`

Any Idea, why this doesn’n work at all.
And on the other side, why do ubuntu (or webmin) lost the ipv4 address (but not the ipv6) from time to time. Might this be a bug of webmin?

I got it.
I missed to put eth0 into double-quotes.
now it works as expected.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.