02-02-2025, 08:47 PM
(05-06-2022, 01:29 PM)robthebold Wrote: I wonder if there's anything I can do script-wise that can periodically check on cellular connectivity and alert me that I should reboot the phone. I'll post if I find anything useful on that.
Sorry for reviving a dead thread, but I could not see your profile to pm you and I saw that your account seems to still be active.
Here is a script that you can put in either your user or the root's crontab depending on if you want your phone to reboot automatically upon a modem crash.
Here is the ugly script that I use to do that and I adapted it with notify-send if you would rather have notifications instead of a cold reboot.
Notes
- this assumes a non systemd distro (I am not familiar with systemd) (iirc, you use postmarketos)
- It is not php code, it is only the text editor that puts that title
Desktop notification on modem crash (non automatic reboot)
0. Create the directory `/opt/sbin/`
Code:
# mkdir -p /otp/sbin
1. Put this script in `/opt/sbin/modem-check`
PHP Code:
#!/bin/sh
export LANG="en_US.UTF-8"
MODEM_STATE=`nmcli device|grep cdc-wdm0|head -n1|xargs|cut -f3 -d' '`
MODEM_STATE_CONNECTED="connected"
if [ "$MODEM_STATE" != "$MODEM_STATE_CONNECTED" ]; then
notify-send "Modem crashed. Reboot in order to bring it back online."
fi
2.1 Open the crontab for your user (not root, not through sudo)
PHP Code:
$ crontab -e
2.2 Add the following line at the bottom of your crontab
PHP Code:
*/30 * * * * /opt/sbin/modem-check
2.3 Save it and quit
3. Enable crond
PHP Code:
# rc-update add crond
4. Start crontab monitoring without rebooting
PHP Code:
# rc-service crond start
Automatic reboot on modem crash
If you want to reboot your phone automatically (Be careful, as you could experience data loss if you are using the phone while the phone reboots)
0. Create the directory `/opt/sbin/`
PHP Code:
# mkdir /otp/sbin
1. Put the script code in `/opt/sbin/modem-check`
PHP Code:
#!/bin/sh
export LANG="en_US.UTF-8"
MODEM_STATE=`nmcli device|grep cdc-wdm0|head -n1|xargs|cut -f3 -d' '`
MODEM_STATE_CONNECTED="connected"
LOG="/var/log/modem-check-crash"
if [ "$MODEM_STATE" != "$MODEM_STATE_CONNECTED" ]; then
echo "`date '+%Y-%m-%d %T'`: modem crashed, rebooting." >> "$LOG"
reboot
fi
2.1 Open the crontab for the root user
PHP Code:
# crontab -e
2.2 Add the following line at the bottom of the root's crontab
PHP Code:
*/30 * * * * /opt/sbin/modem-check
2.3 Save it and quit
3. Enable crond
PHP Code:
# rc-update add crond
4. Start crontab monitoring without rebooting
PHP Code:
# rc-service crond start