Restart the network manager via cron

instead of rebooting I’d like to just restart the network connection while I’m asleep. How would I do it? I tried systemctl restart networking but the networking service is not found.
Thanks

Assuming the network interface is eth0:

ip link set eth0 down
ip link set eth0 up

It needs to be run either from root or using sudo.

I’m on wlan0.
Can I add it to crontab or should I put it in a shell script?

Normally, you’d create a shell script and then run it from cron. That way, you can add some error checks to the script.

1 Like

did that, now how could I print something like a success message into a log?

Just Google crontab and bash script. You either can have the script returning a value which cron then will write to log or you can in the script use something like logger

doesn’t work. It reconnects but I don’t get internet access. Guess I stick with shutdown -r

Indeed, it loses the IP address on wlan0. Probably a connman limitation.

I tried this on a Pi3 / wlan0 and it does work:

/usr/bin/connmanctl disconnect wifi_<string of characters>_managed_psk
/usr/bin/connmanctl connect wifi_<string of characters>_managed_psk

Run connmanctl services to get your SSID’s unique “string of characters”.

EDit: Fix typo. Thanks @thobu

hey, thanks for getting back. should these commands run under sudo crontab? Or just crontab?

this seems to work, great! I’m getting connectivity. I’ll see if the cron job fires properly in the morning.
btw @dillthedog the path should have /usr/ instead of /use/

1 Like