Can it be done? Yes. Should it be done? Probably not. Most operational problems can be solved without rebooting. You also risk your script causing a boot loop and making the router completely inaccessible.
Yes I understand what ur saying.. but the issue I'm facing can only be solved by reboot. It happens randomly every 2 - 3 days.
If u search about it.. u will know.
phy0 rt2x00queue_write_tx_frame error – dropping frame due to full tx queue 2
So I just want to make a script to detect this line and reboot. I can't update my router to the latest version due to usb not working issue. So this is the only solution I could think of.
I was wondering could someone please make the script for me like @ulmwind mentioned since I'm not quite familiar with this language if u don't mind. I would really appreciate it..
That's only the comparison part. You need to put it inside the do loop that @ulmwind posted to have it wait for new lines to be posted to the log and compare each one.
The shell in OpenWrt is ash; it is very similar to bash but missing some of the more advanced features. Look for a reference on ash or bash to learn the language.
Save this script, e.g. /root/phy0-watch.sh. Run it with /bin/sh /root/phy0-watch.sh
#!/bin/sh
sig="rt2x00queue_write_tx_frame error"
logread -f | while read line; do
if [ "${line#*$sig*}" != "$line" ]; then
echo reboot # remove the "echo" if it works
fi
done
Then you can test it by running in another terminal
logger phy0 rt2x00queue_write_tx_frame error – dropping frame due to full tx queue 2
I did as mentioned, then next error when sending this command 'pservice restart'
root@OpenWrt:~# /etc/init.d/pservice restart
/etc/rc.common: eval: line 1: uci_load_validate: not found
/etc/rc.common: line 1: uci_load_validate: not found