Thanks, but the issue is not the path in the crontab. I already have an absolute path to the Python script in crontab. And there are other bash/shell commands within the Python script that run just fine. It's only turning off the wifi connection that doesn't work.
These shell commands work OK even when cron is the one running the script:
- iperf3 to measure network speed
- ps aux to check if rsync is running
- sending text to /dev/pts/0 to warn me that the network is about to get reset
All of these work OK, it's just the nmcli commands that get skipped when running the script via cron. If I manually run it from a terminal, everything works.
Here is a piece of the Python script though you don't really need it to understand the problem that I'm having.
Code:
def reset_network(speed):
message = (datetime.datetime.now().strftime('%a %H:%M: ') + f'Network is {speed} MB/s. Restarting in 15 seconds.').encode()
pts = os.open('/dev/pts/0', os.O_RDWR)
os.write(pts, message)
time.sleep(15)
subprocess.run('nmcli radio wifi off'.split(' '))
time.sleep(6)
subprocess.run('nmcli radio wifi on'.split(' '))
os.close(pts)
Bookmarks