What's new

Help with writing a simple "wl radio off && wl radio on" script!! please!!

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Adam Popiel

Occasional Visitor
Basically, I bought some wifi lightbulbs and I can pair them with my wifi and the app on the phone and everything works good, but then when i accidentally turn them off on the wall, they dont fully connect back to the router although it shows that its connected to the wifi, i found in the logs that its not fully connecting. Only after i turn off wifi and turn back on does the light bulb work on the app again.



So here are the logs from the bulb once it was turned on at the wall:

Mar 9 05:53:29 dnsmasq-dhcp[8310]: DHCPDISCOVER(br0) c8:2b:96:4e:e7:dd
Mar 9 05:53:29 dnsmasq-dhcp[8310]: DHCPOFFER(br0) 192.168.1.122 c8:2b:96:4e:e7:dd

and it keeps looping like this until i turn off and on the wifi

Here is the moment i run the wl radio off && wl radio on commands:

Mar 9 07:52:08 wlceventd: WLCEVENTD wlceventd_proc_event(401): eth5: Disassoc 40:4E:36:1A:AF:81, status: 0, reason: Disassociated because sending station is leaving (or has left) BSS (8)
Mar 9 07:52:08 wlceventd: WLCEVENTD wlceventd_proc_event(401): eth5: Disassoc 40:4E:36:1A:AF:81, status: 0, reason: Disassociated because sending station is leaving (or has left) BSS (8)



and then in about a minute the lightbulb properly connects to the router and i can control it through my app:

Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPDISCOVER(br0) c8:2b:96:4e:e7:dd
Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPOFFER(br0) 192.168.1.122 c8:2b:96:4e:e7:dd
Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPREQUEST(br0) 192.168.1.122 c8:2b:96:4e:e7:dd
Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPACK(br0) 192.168.1.122 c8:2b:96:4e:e7:dd ZENGGE_35_4EE7DD



So i need something like this for example:


IF the system log shows "dnsmasq-dhcp[8310]: DHCPACK(br0)" in the last 10 lines or in the last 3 minutes, THEN run "wl radio off && wl radio on"


What is the simplest way to achieve this?


I really appreciate all you do in this forum and id be forever grateful if you can help me out.


Best regrds,

Adam Popiel
 
Basically, I bought some wifi lightbulbs and I can pair them with my wifi and the app on the phone and everything works good, but then when i accidentally turn them off on the wall, they dont fully connect back to the router although it shows that its connected to the wifi, i found in the logs that its not fully connecting. Only after i turn off wifi and turn back on does the light bulb work on the app again.



So here are the logs from the bulb once it was turned on at the wall:

Mar 9 05:53:29 dnsmasq-dhcp[8310]: DHCPDISCOVER(br0) c8:2b:96:4e:e7:dd
Mar 9 05:53:29 dnsmasq-dhcp[8310]: DHCPOFFER(br0) 192.168.1.122 c8:2b:96:4e:e7:dd

and it keeps looping like this until i turn off and on the wifi

Here is the moment i run the wl radio off && wl radio on commands:

Mar 9 07:52:08 wlceventd: WLCEVENTD wlceventd_proc_event(401): eth5: Disassoc 40:4E:36:1A:AF:81, status: 0, reason: Disassociated because sending station is leaving (or has left) BSS (8)
Mar 9 07:52:08 wlceventd: WLCEVENTD wlceventd_proc_event(401): eth5: Disassoc 40:4E:36:1A:AF:81, status: 0, reason: Disassociated because sending station is leaving (or has left) BSS (8)



and then in about a minute the lightbulb properly connects to the router and i can control it through my app:

Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPDISCOVER(br0) c8:2b:96:4e:e7:dd
Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPOFFER(br0) 192.168.1.122 c8:2b:96:4e:e7:dd
Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPREQUEST(br0) 192.168.1.122 c8:2b:96:4e:e7:dd
Mar 9 07:52:55 dnsmasq-dhcp[8310]: DHCPACK(br0) 192.168.1.122 c8:2b:96:4e:e7:dd ZENGGE_35_4EE7DD



So i need something like this for example:


IF the system log shows "dnsmasq-dhcp[8310]: DHCPACK(br0)" in the last 10 lines or in the last 3 minutes, THEN run "wl radio off && wl radio on"


What is the simplest way to achieve this?


I really appreciate all you do in this forum and id be forever grateful if you can help me out.


Best regrds,

Adam Popiel
Not sure if you can still exploit dnsmasq's
Code:
dhcp-script=/sbin/dhcpc_lease
to plug-in your own script to be executed first, then call '/sbin/dhcpc_lease' when your script ends?

So I suspect you may have to resort to a crude script such as SyslogEventMonitor.sh and customise/adapt it to your needs

e.g. When you get the first 'DOWN' messages for device 'c8:2b:96:4e:e7:dd' then restart the radio.
Code:
MSG0001T="Light Bulb Monitor"                       # Title for Syslog messages/SendMail
MSG0001C=0                                          # DOWN message count
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:e7:dd"      # DOWN Trigger message
MSG0001U="DHCPACK(br0) 192.168.1.122 c8:2b:96:4e:e7:dd ZENGGE_35_4EE7DD"    # UP message: Reset monitoring/recovery action message
MSG0001XU=                                          # UP   action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh"          # DOWN action script
and create the recovery action script

/jffs/scripts/Restart_Radio.sh
Code:
echo -e "#!/bin/sh\n\nVER=\"1.01\"\n\nLOCKFILE=\"/tmp/\$(basename \$0)-flock\"\nFD=149\neval exec \"\$FD>\$LOCKFILE\"\nflock -n \$FD || { logger -st \"\$(basename \$0)\" \$\$ \"\$VER ALREADY running...ABORTing\"; exit; }\n\nlogger -st \"(\$(basename \$0))\" \$\$ \"\$VER Restarting Radio.....\"\nwl radio off && wl radio on\n\nsleep 300" > /jffs/scripts/Restart_Radio.sh;chmod +x /jffs/scripts/Restart_Radio.sh
 
Last edited:
Thank you soo much for the fast response @Martineau .

So im still new to this but what i understand is to paste what you wrote into the script correct?

FD=120
eval exec "$FD>$LOCKFILE"
flock -n $FD || { Say "Syslog Event monitor ALREADY running...ABORTing"; exit; }


sleep 1
echo -e $(date)" Syslog Event Monitor started.....PID="$$ >> $LOCKFILE

# Define Trigger messages
#
# DOWN message count (to allow for controlling the trigger/action etc.)
# DOWN trigger message
# DOWN trigger ACTION script
# UP trigger message
# UP trigger ACTION script

#------------------------------------Start of customisation-------------------- >
MSG0001T="Light Bulb Monitor" # Title for Syslog messages >
MSG0001C=0 # DOWN message count
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:e7:dd" # DOWN Trigger message
MSG0001U="DHCPACK(br0) 192.168.1.122 c8:2b:96:4e:e7:dd ZENGGE_35_4EE7DD" # U >
MSG0001XU= # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh" # DOWN action script
#------------------------------------End of customisation---------------------- >


# Track the Syslog events

tail -F /tmp/syslog.log | \
while read SYSLOG
do
case "$SYSLOG" in
*$MSG0001D*|*$MSG0001U*) >
TAG="$MSG0001T"
REASON="Trigger"
case "$SYSLOG" in
*$MSG0001D*) ) >
MSG0001C=$((1+MSG0001C)) >
ACTION=$MSG0001XD >
if [ $MSG0001C -eq 1 ]; >
REASON="unexpec >
SyslogEmail
 
So im still new to this but what i understand is to paste what you wrote into the script correct?
Yes

Whilst you won't get any emails (until you edit the script with your email credentials etc.) having defined the event MSG* variables, you should be able to run the script (assuming you are familiar with scripting - if not see the Wiki/documentation for Asuswrt-merlin for hints/examples of scripting etc.) in a terminal, then flick the lights OFF/ON and see if the script detects the events.
 
Ok, another question?


Can i have multiple trigger down messages?? and then multiple trigger up messages that correspond to another device?

MSG0001T="Light Bulb Monitor" # Title for Syslog messages/SendMail
MSG0001C=0 # DOWN message count
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bb" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bc" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bd" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:be" # DOWN Trigger message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bb" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bc" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bd" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:be" # UP message: Reset monitoring/recovery action message
MSG0001XU= # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh" # DOWN action script


will something like this work?
 
also one more question?
echo -e "#! /bin/sh\nlogger -st \"(\$(basename \$0))\" \"Restarting Radio.....\"\nwl radio off && wl radio on" > /jffs/scripts/Restart_Radio.sh;chmod +x /jffs/scripts/Restart_Radio.sh

nwl radio off && wl radio on

or does it need to be wl radio off && wl radio on
 
so i got the script working, kind of:

Mar 12 12:35:33 dnsmasq-dhcp[16758]: DHCPACK(br0) 192.168.1.117 c8:2b:96:4e:e4:24 ZENGGE_35_4EE424

but then the script gets run again for some reason:

Mar 12 12:38:38 dnsmasq-dhcp[16758]: DHCPDISCOVER(br0) c8:2b:96:4e:e4:24
Mar 12 12:38:38 dnsmasq-dhcp[16758]: DHCPOFFER(br0) 192.168.1.117 c8:2b:96:4e:e4:24
 

Attachments

  • syslog (6).txt
    23.7 KB · Views: 174
and now its restarting radio all the time



apopiel85@RT-AC86U-61D0:/jffs/scripts# ./SyslogEventMonitor.sh
(SyslogEventMonitor.sh): 21862 v1.01 Syslog Event Monitor started.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
 
also one more question?
echo -e "#! /bin/sh\nlogger -st \"(\$(basename \$0))\" \"Restarting Radio.....\"\nwl radio off && wl radio on" > /jffs/scripts/Restart_Radio.sh;chmod +x /jffs/scripts/Restart_Radio.sh

nwl radio off && wl radio on

or does it need to be wl radio off && wl radio on

Not sure what you are reporting? :confused:…... the 'wl radio off' command is created correctly in the target 'Restart_Radio.sh' script?
Code:
echo -e "#! /bin/sh\nlogger -st \"(\$(basename \$0))\" \"Restarting Radio.....\"\nwl radio off && wl radio on" > /jffs/scripts/Restart_Radio.sh;chmod +x /jffs/scripts/Restart_Radio.sh

cat Restart_Radio.sh

#! /bin/sh
logger -st "($(basename $0))" "Restarting Radio....."
wl radio off && wl radio on
 
so i got the script working, kind of:

Mar 12 12:35:33 dnsmasq-dhcp[16758]: DHCPACK(br0) 192.168.1.117 c8:2b:96:4e:e4:24 ZENGGE_35_4EE424

but then the script gets run again for some reason:

Mar 12 12:38:38 dnsmasq-dhcp[16758]: DHCPDISCOVER(br0) c8:2b:96:4e:e4:24
Mar 12 12:38:38 dnsmasq-dhcp[16758]: DHCPOFFER(br0) 192.168.1.117 c8:2b:96:4e:e4:24
From the Syslog it shows that @12:35:30 the monitor triggered the execution of the recovery script for the first instance of the DOWN message and 3 seconds later @12:35:33 the script reset itself on recognising the UP message:
Code:
Mar 12 12:35:30 dnsmasq-dhcp[16758]: DHCPDISCOVER(br0) c8:2b:96:4e:e4:24
Mar 12 12:35:30 dnsmasq-dhcp[16758]: DHCPOFFER(br0) 192.168.1.117 c8:2b:96:4e:e4:24
Mar 12 12:35:30 (SyslogEventMonitor.sh): 21862 Light Bulb Monitor unexpected restart detected; Action='/jffs/scripts/Restart_Radio.sh'
Mar 12 12:35:30 (SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
Mar 12 12:35:30 (Restart_Radio.sh): Restarting Radio.....

<snip>

Mar 12 12:35:33 dnsmasq-dhcp[16758]: DHCPDISCOVER(br0) c8:2b:96:4e:e4:24
Mar 12 12:35:33 dnsmasq-dhcp[16758]: DHCPOFFER(br0) 192.168.1.117 c8:2b:96:4e:e4:24
Mar 12 12:35:33 dnsmasq-dhcp[16758]: DHCPREQUEST(br0) 192.168.1.117 c8:2b:96:4e:e4:24
Mar 12 12:35:33 dnsmasq-dhcp[16758]: DHCPACK(br0) 192.168.1.117 c8:2b:96:4e:e4:24 ZENGGE_35_4EE424
Mar 12 12:35:33 (SyslogEventMonitor.sh): 21862 Light Bulb Monitor re-initialised; Action=''

Three minutes later @12:38:39 the DOWN message was again detected:
Code:
Mar 12 12:38:38 dnsmasq-dhcp[16758]: DHCPOFFER(br0) 192.168.1.117 c8:2b:96:4e:e4:24
Mar 12 12:38:39 (SyslogEventMonitor.sh): 21862 Light Bulb Monitor unexpected restart detected; Action='/jffs/scripts/Restart_Radio.sh'
Mar 12 12:38:39 (SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
Mar 12 12:38:39 (Restart_Radio.sh): Restarting Radio.....
Clearly the monitor/recovery cycle worked as expected?
 
Last edited:
and now its restarting radio all the time



apopiel85@RT-AC86U-61D0:/jffs/scripts# ./SyslogEventMonitor.sh
(SyslogEventMonitor.sh): 21862 v1.01 Syslog Event Monitor started.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
./SyslogEventMonitor.sh: line 231: can't create : nonexistent directory
(Restart_Radio.sh): Restarting Radio.....
(SyslogEventMonitor.sh): 21862 e-mail sent using curl smtps:// SSL/TLS (non-Certificate) mysmtp.server.com:nnn
Without a timestamp it is impossible to determine the spurious restart cycle interval, but perhaps the recovery 'Restarting Radio.sh' script needs to be modified to prevent multiple concurrent executions (or at least add the PID to the message) and perhaps throttle the execution of the script to say once every 5 minutes?
 
Hey @Martineau


Can i have multiple trigger down messages?? and then multiple trigger up messages that correspond to another device?

MSG0001T="Light Bulb Monitor" # Title for Syslog messages/SendMail
MSG0001C=0 # DOWN message count
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bb" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bc" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bd" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:be" # DOWN Trigger message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bb" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bc" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bd" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:be" # UP message: Reset monitoring/recovery action message
MSG0001XU= # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh" # DOWN action script
 
@Martineau or do i have to have separate script for each lightbulb?

And also, MSG0001C=0 is the message count so for example if i want to see 4 messages before running the script i will put MSG0001C=3, right?
 
do i have to have separate script for each lightbulb?
Well you could, but at the moment the script only allows one instance to be running.
However, if you modify each script instance to use a unique File Descriptor
Code:
FD=120
i.e.
Code:
c8:2b:96:4e:94:bb monitor script uses FD=120
c8:2b:96:4e:94:bc monitor script uses FD=121
etc.
it would probably work but I wouldn't recommend it.
And also, MSG0001C=0 is the message count so for example if i want to see 4 messages before running the script i will put MSG0001C=3, right?
No, the current script will only trigger on the first occurrence of the DOWN Message (on the assumption that the DOWN event message is unique)

You will need to download v1.02 of the script then you would use
Code:
MSG0001C=4
to trigger the DOWN process only on the 4th event message.
(I noticed I'd locally changed it sometime since originally uploading v1.01 back in Oct'2018, but never uploaded v1.02 publicly)
Can i have multiple trigger down messages?? and then multiple trigger up messages that correspond to another device?
The crude script was originally written to catch unique system message pairs

i.e. 1 DOWN message + 1 UP message

So using the current script would need you to replicate the MSG000* 'case' clause for each device
(see the comment for MSG999* clause)
Code:
*$MSG0001D*)                                    # DOWN event for c8:2b:96:4e:94:bb
*$MSG0002D*)                                    # DOWN event for c8:2b:96:4e:94:bc
etc.
So depending on the number of devices this would be inefficient as the script would grow unnecessarily large.

Alternatively (but better than tediously replicating the MSG000* clause for each device) you could keep the MSG0001D simple and generic
Code:
MSG0001D="DHCPDISCOVER(br0)"
then create another custom variable containing the list of Lightbulb MACs
Code:
MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"
and modify the DOWN process
Code:
SyslogEmail                             # Email etc.
Process_ACTION
to
Code:
[ -n "$(echo "$SYSLOG" | grep -oE "$MAC_LIST")" ] && { SyslogEmail; Process_ACTION; }
so effectively you will now check if the MAC matches in the DOWN message

"DHCPDISCOVER(br0) xx:xx:xx:xx:xx:xx"
and only execute the recovery action if it does.


 
Last edited:
Hey @Martineau,

once again , thanks for all the help. I really appreciate it. I'd definitely want to go with the last option. Where in the script would i need to put the MAC variable:

MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"


MSG0001T="Light Bulb Monitor" # Title for Syslog messages/SendMail
MSG0001C=0 # DOWN message count
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bb" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bc" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:bd" # DOWN Trigger message
MSG0001D="DHCPDISCOVER(br0) c8:2b:96:4e:94:be" # DOWN Trigger message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bb" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bc" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:bd" # UP message: Reset monitoring/recovery action message
MSG0001U="DHCPACK(br0) 192.168.1.74 c8:2b:96:4e:94:be" # UP message: Reset monitoring/recovery action message
MSG0001XU= # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh" # DOWN action script
MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"




Does it need to look something like this?
 
Hey @Martineau,

once again , thanks for all the help. I really appreciate it. I'd definitely want to go with the last option. Where in the script would i need to put the MAC variable:
MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"
You would code
Code:
MSG0001T="Light Bulb Monitor"                  # Title for Syslog messages/SendMail
MSG0001C=-99999                                # DOWN message count
MSG0001D="DHCPDISCOVER(br0)"                   # DOWN Trigger message
MSG0001U="DHCPACK(br0)"                        # UP message: Reset monitoring/recovery action message
MSG0001XU=                                     # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh"     # DOWN action script

MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"
So now that the new DOWN/UP trigger messages are generic, you don't need the following 'if' clause:
Code:
if [ $MSG0001C -eq 1 ];then
checking if the trigger count MSG0001C matches (either 1 or 4 etc.), because you want every $MSG0001D/$MSG0001U trigger to be scanned to see if it contains one of the Lightbulb MACs in your list.
 
Last edited:
Hi @Martineau, thanks for the replay!

So I've changed the v.1.02 script to look like something like this:


MSG0001T="Light Bulb Monitor" # Title for Syslog messages/SendMail
MSG0001C=-99999 # DOWN message count
MSG0001D="DHCPDISCOVER(br0)" # DOWN Trigger message
MSG0001U="DHCPACK(br0)" # UP message: Reset monitoring/recovery action message
MSG0001XU= # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh" # DOWN action script

MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"


and i also put this line into my router:

apopiel85@RT-AC86U-61D0:/tmp/home/root# [ -n "$(echo "$YSLOG" | grep -oE "$MAC_L
IST")" ] && { SyslogEmail; Process_ACTION; }
apopiel85@RT-AC86U-61D0:/tmp/home/root#


Is there anything im missing now?

I will obviously change the MAC addresses to match those of the lightbulbs but I need to know the code is good. I will test tonight when I get back home from work.


I've also uploaded the whole code that I edited, maybe you can see it and upload it back with any corrections if they are needed.


Once again, I really appreciate all the help I'm getting from you.
 

Attachments

  • syslogeventmonitor.txt
    7.2 KB · Views: 210
@Martineau ,Do i put this command into the script or i just run it once on my router???


[ -n "$(echo "$YSLOG" | grep -oE "$MAC_LIST")" ] && { SyslogEmail; Process_ACTION; }
 
@Martineau ,Do i put this command into the script or i just run it once on my router???


[ -n "$(echo "$SYSLOG" | grep -oE "$MAC_LIST")" ] && { SyslogEmail; Process_ACTION; }

<sigh> :rolleyes:
It is script code.....

Download your custom specific v1.03 of the script and make sure you recreate the Restart_Radio.sh from post #2
 
@Martineau ,

so you put this command somewhere inside the script??
[ -n "$(echo "$SYSLOG" | grep -oE "$MAC_LIST")" ] && { SyslogEmail; Process_ACTION; }

also, in version 1.02, you mentioned to use:

Code:
MSG0001T="Light Bulb Monitor" # Title for Syslog messages/SendMail
MSG0001C=-99999 # DOWN message count
MSG0001D="DHCPDISCOVER(br0)" # DOWN Trigger message
MSG0001U="DHCPACK(br0)" # UP message: Reset monitoring/recovery action message
MSG0001XU= # UP action script
MSG0001XD="/jffs/scripts/Restart_Radio.sh" # DOWN action script

MAC_LIST="c8:2b:96:4e:94:bb|c8:2b:96:4e:94:bc|c8:2b:96:4e:94:bd"


MSG0001C=-99999, but in the new code for me v1.03 i see that this is set to 0. is this correct?
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top