[SOLVED] Script is not working...

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Advanced Networking
Author Message
AlphaCJ44
DD-WRT Novice


Joined: 01 Jan 2021
Posts: 16

PostPosted: Wed Jan 20, 2021 6:20    Post subject: [SOLVED] Script is not working... Reply with quote
Hello,

Not sure if this is the right place to ask this but i am trying to run a script at startup which will detect a string from system log and run few commands...

Code:
#!/bin/sh
dec="wan : WAN is up"
logread -f | while read line; do
    if [ "${line#*$dec*}" != "$line" ]; then
        sleep 3; stopservice nas; wlconf eth1 down; wlconf eth2 down; wlconf eth1 up; wlconf eth2 up; startservice nas; logger "VAP workaround executed";
    fi
done


I know this can be done via .wanup script but for some reason i really need it to work this way.

The file is stored in my samba storage (/opt/config/detect.sh) and i am executing it with ./detect.sh, i made it executable with chmod a+x.

Problem is nothing seems to be happening when i run command
Code:
logger wan : WAN is up



Am i doing it correctly?
Or is there an alternative (better) way of doing this.

Will really appreciate any help.

Regards!
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 7268
Location: Netherlands

PostPosted: Wed Jan 20, 2021 10:09    Post subject: Reply with quote
I will transfer your question to the advanced networking forum.

I have not looked in detail but I would use something like:
Code:
grep -q 'WAN is up' /var/log/messages && echo "WAN is up"


But there are other ways to see if the WAN is up, I personally use a ping test via the WAN like:
Code:
PINGIP="8.8.8.8"
INTERFACE=$(get_wanface)
while ! ping -qc1 -W6 -n $PINGIP -I $INTERFACE &> /dev/null; do


There is also an NVRAM variable "wanup"

Take note if you use a script from storage then the script is probably not executed from startup as it takes often more than 10 seconds before the storage is on line.

Recent builds have a utility: is-mounted.sh which waits till the storage is up, it works like:
Code:
is-mounted.sh /opt


Quote:
# wait until directory is mounted and writable
# usage: is-mounted.sh /name-of directory
# default is /jffs

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
WireGuard Documents & Guides:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327397
OpenVPN Documents & Guides: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327398
IPSET: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261
Install guide R6400v2:http://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
AlphaCJ44
DD-WRT Novice


Joined: 01 Jan 2021
Posts: 16

PostPosted: Thu Jan 21, 2021 9:09    Post subject: Reply with quote
Thanks... That pretty much solved it.
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1089
Location: Appalachian mountains, USA

PostPosted: Thu Jan 21, 2021 16:11    Post subject: Reply with quote
I have multiple sleep/grep loops in my startup code to watch the log for events, but the OP suggested the construct logread -f | while read line; do... ; done, which is actually much nicer because the loop body is invoked whenever a new line appears in the log. There is no arbitrary sleep time, so synchronization would be tighter.

I'm still on 44048, as I have Apple clients talking to one of those Linksys/Marvell wonderrouters, but I see that even so, logread is there (as a symbolic link to busybox, like other built-ins). However, any attempt to use it yields

logread: can't find syslogd buffer: No such file or directory

So I'm curious. Is it usable only in later builds? Or not at all? Or "coming soon to a router near you"?

_________________
Five WRT1900ACSv2's on 42926, 44048.
VLANs, VAPs, NAS, client-mode travel router, OpenVPN client (AirVPN), DDNS, wireguard servers, wireguard clients (AzireVPN), two DNSCrypt DNS providers (incl Quad9) via OpenVPN/wireguard clients.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 7268
Location: Netherlands

PostPosted: Thu Jan 21, 2021 16:32    Post subject: Reply with quote
I think you have to start syslogd first with something like (do not know the exact syntax):
/sbin/syslogd -C24

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
WireGuard Documents & Guides:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327397
OpenVPN Documents & Guides: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327398
IPSET: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261
Install guide R6400v2:http://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1089
Location: Appalachian mountains, USA

PostPosted: Thu Jan 21, 2021 16:36    Post subject: Reply with quote
egc wrote:
I think you have to start syslogd first with something like (do not know the exact syntax):
/sbin/syslogd -C24

Sorry... I should have said: syslogd is already running. ps shows it was started as syslogd -Z -L. I checked those args and learned that -L requests local logging (not just over the network), and -Z causes times in log entries to be shown in the local timezone.

_________________
Five WRT1900ACSv2's on 42926, 44048.
VLANs, VAPs, NAS, client-mode travel router, OpenVPN client (AirVPN), DDNS, wireguard servers, wireguard clients (AzireVPN), two DNSCrypt DNS providers (incl Quad9) via OpenVPN/wireguard clients.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 7268
Location: Netherlands

PostPosted: Thu Jan 21, 2021 16:43    Post subject: Reply with quote
I think it needs the -C24 (24Kb shared memory buffer) so that logread can read it, but no expert in these matters
_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
WireGuard Documents & Guides:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327397
OpenVPN Documents & Guides: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327398
IPSET: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261
Install guide R6400v2:http://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum