I have a machine that reboots nightly, but when it does it ends up connecting to the wrong router somehow, and always gets the wrong IP. I don't want it to use a static IP, I have my router issue it a reserved address.
Anyway, it's easily fixed by renewing the DHCP lease (Ethernet, not wifi), but I want this to be automated after the reboot. I can't get this to work from cron for some reason... I've tried both of these:
* * * * * echo "add State:/Network/Interface/en0/RefreshConfiguration temporary" | sudo scutil * * * * * sudo ipconfig set en0 DHCP
Neither does anything from Cron, but works fine from the CLI manually.
How can I get this to work via cron?
EDIT: I have tried using the root user as suggested in the first answer, but this also does nothing. No change, nothing output to a log, just nothing.