Solved: Detect IPv6 packets via CRON / script issue.

Post new topic   Reply to topic    DD-WRT Forum Index -> Marvell MVEBU based Hardware (WRT1900AC etc.)
Author Message
dpp3530
DD-WRT Guru


Joined: 12 Dec 2007
Posts: 761
Location: Pittsburgh, PA USA

PostPosted: Mon Oct 04, 2021 20:42    Post subject: Solved: Detect IPv6 packets via CRON / script issue. Reply with quote
I have Verizon as my ISP, and they have not yet rolled out IPV6 to all locations. While reading the DSLReports.com forums on Verizon and IPV6, I found a script that someone wrote for PFSense that uses TCPDump to listen for IPV6 RA packets, thereby letting you know when IPV6 gets turned up in your area. After installing a few things in Entware (coreutils-timeout, mstmp, and busybox), I was able to adapt the script to run under DD-WRT r47225 (and subsequent releses). It's installed on a USB thumbdrive partition mounted as /jffs. I should add that this is on a WRT1900AC v1.

The script is intended to run once per day and listen for 5 minutes, then if a packet is detected, send an email notifying me. It also logs the start and end of the script in the system log. I have syslogd and klogd enabled.

If I run the script from the command line (SSH), it listens for 5 minutes and the two log entries are exactly 5 minutes apart. If I run it from a cron job, the end entry immediately follows the start entry, meaning it didn't listen for any time at all. I thought the difference in behavior had to do with it not running under root access, but I think I've ruled that out. The script is supposed to run at 5:01AM.

Currently my cron entry is:
1 5 * * * root sh /jffs/v6test.sh

But I've also tried
1 5 * * * sh /jffs/v6test.sh
1 5 * * * root /jffs/v6test.sh

I'm hoping someone can help me figure out what I'm doing wrong. I have searched the forums, the wiki, and anything else on Google related to Cron jobs.

The code for the script is below (email address redacted):

Code:
#!/bin/sh

# set the variable below to your FIOS interface
IF=eth1
logger -t v6test "Starting daily scan for IPV6"
timeout 300 tcpdump -ni ${IF} 'icmp6 && ip6[40] == 134' -c 10 >/tmp/${IF}_RAs.out
FSIZE=$(stat /tmp/${IF}_RAs.out)
FSIZE2=$(echo $FSIZE | cut -c33-34)
echo $FSIZE2
if [ "$FSIZE2" -gt 1 ]; then
  logger -t v6test "RA packet detected on eth1 $0"
  cat /jffs/mail.txt | msmtp -a gmail redacted@mydomain.com
fi
logger -t v6test "End scan for IPV6"

_________________
__________________________
Netgear R7800
DD-WRT v3.0 STD
Linksys WRT1900AC
DD-WRT v3.0 STD


Last edited by dpp3530 on Fri Dec 10, 2021 19:05; edited 1 time in total
Sponsor
Ostddwrt
DD-WRT Novice


Joined: 31 Aug 2018
Posts: 18
Location: FL

PostPosted: Sun Nov 21, 2021 3:48    Post subject: Reply with quote
Quote:
I was able to adapt the script to run under DD-WRT r47225

Have you tried a different build?

I've read here some builds may have broken cron.

_________________
DD-WRT V3.0-r49626 std (08/03/22) on WRT3200ACM and flying...
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14102
Location: Texas, USA

PostPosted: Sun Nov 21, 2021 4:08    Post subject: Reply with quote
Ostddwrt wrote:
Quote:
I was able to adapt the script to run under DD-WRT r47225

Have you tried a different build?

I've read here some builds may have broken cron.

Quote:
Running on build 41586 (11/21/19) on a wrt1900acsv2

Interjection of irrelevant information as cron was fixed already.

https://svn.dd-wrt.com/ticket/6916

https://svn.dd-wrt.com/changeset/41702

https://svn.dd-wrt.com/changeset/41189

https://svn.dd-wrt.com/ticket/6824

https://svn.dd-wrt.com/ticket/6744

There is *this* ticket, that doesn't seem like it was ever followed up on, though:

https://svn.dd-wrt.com/ticket/6688

CRON DD-WRT Wiki: https://forum.dd-wrt.com/wiki/index.php/CRON

_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
dpp3530
DD-WRT Guru


Joined: 12 Dec 2007
Posts: 761
Location: Pittsburgh, PA USA

PostPosted: Sun Nov 21, 2021 14:37    Post subject: Reply with quote
Ostddwrt wrote:
Quote:
I was able to adapt the script to run under DD-WRT r47225

Have you tried a different build?

I've read here some builds may have broken cron.


I've tried most of the newer builds since 47225. I'm on 47656 right now and it's still happening

Code:
root@Barricade:/tmp/var/log# cat messages | grep v6test
Nov 21 09:19:00 Barricade user.notice v6test: Starting daily scan for IPV6
Nov 21 09:19:00 Barricade user.notice v6test: End scan for IPV6
Nov 21 09:20:32 Barricade user.notice v6test: Starting daily scan for IPV6
Nov 21 09:25:32 Barricade user.notice v6test: End scan for IPV6


The first two are from the CRON job, where the last two lines are a manual run.

Timeout is running of a USB stick. One of those links seemed to indicate that might be related.

_________________
__________________________
Netgear R7800
DD-WRT v3.0 STD
Linksys WRT1900AC
DD-WRT v3.0 STD
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Thu Dec 09, 2021 12:17    Post subject: Reply with quote
I have a possible solution, remove the .sh extension from the cron script path and dont forget to make it executable.

Let me know how that goes.

Take care.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12812
Location: Netherlands

PostPosted: Thu Dec 09, 2021 12:24    Post subject: Reply with quote
just a hunch put an & behind the cron entry so that the script will continue running in the background?
_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: 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
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14102
Location: Texas, USA

PostPosted: Thu Dec 09, 2021 17:45    Post subject: Reply with quote
Ash is bash compatible on this device, it's not a micro build. Likely no need to remove the .sh extension, lol.
_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
dpp3530
DD-WRT Guru


Joined: 12 Dec 2007
Posts: 761
Location: Pittsburgh, PA USA

PostPosted: Fri Dec 10, 2021 10:35    Post subject: Reply with quote
The & seemed like a good call, but sadly, it didn't make any difference. I also tried removing the .sh extension, and ran chmod +x each time I renamed the file. When that didn't work, I tried every variant I could think of between the two. Best case, it did the same as before, ran for less than a second. Worst case, it didn't run at all.

My experience with bash is limited to DD-WRT, and this is really the first time I tried to do anything in cron. My job involves a lot of Windows Powershell. I'm explaining my backstory in case my next question is stupid or obvious.

Do I need to enclose the command in quotes or brackets or something to make sure cron reads the whole command?

_________________
__________________________
Netgear R7800
DD-WRT v3.0 STD
Linksys WRT1900AC
DD-WRT v3.0 STD
dpp3530
DD-WRT Guru


Joined: 12 Dec 2007
Posts: 761
Location: Pittsburgh, PA USA

PostPosted: Fri Dec 10, 2021 19:04    Post subject: Reply with quote
I figured it out. I had to modify the script to include explicit paths to the various commands. I guess it couldn't find timeout or some of the other commands.

Anyone else on Verizon FIOS is welcome to steal the script. It can certainly be modified to search for other types of traffic as well.

Thanks to all who offered suggestions. I love this community.

Code:

#!/bin/sh

# set the variable below to your FIOS interface
IF=eth1
logger -t v6test "Starting daily scan for IPV6"
/opt/bin/timeout 5m /opt/sbin/tcpdump -ni ${IF} 'icmp6 && ip6[40] == 134' -c 10 >/tmp/${IF}_RAs.out
FSIZE=$(/opt/bin/stat /tmp/${IF}_RAs.out)
FSIZE2=$(echo $FSIZE | cut -c33-34)
echo $FSIZE2
if [ "$FSIZE2" -gt 1 ]; then
  logger -t v6test "RA packet detected on eth1 $0"
  cat /jffs/mail.txt | /opt/bin/msmtp -a gmail redacted@mydomain.com
fi
logger -t v6test "End scan for IPV6"

_________________
__________________________
Netgear R7800
DD-WRT v3.0 STD
Linksys WRT1900AC
DD-WRT v3.0 STD
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14102
Location: Texas, USA

PostPosted: Fri Dec 10, 2021 19:36    Post subject: Reply with quote
Glad you solved it; I don't think modifying $PATH is readily available via startup script due to the main flash filesystem being read-only, but doesn't Entware automatically add the path to command binaries? I knew somehow there was a missing "link" that was the issue, though. Now we know Cool
_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
Ostddwrt
DD-WRT Novice


Joined: 31 Aug 2018
Posts: 18
Location: FL

PostPosted: Sun Dec 12, 2021 12:35    Post subject: Reply with quote
Good to know issue is addressed and gone.

Explicit full path is always the best way to go in Linux/Unix world.

Lesson learned.

dpp3530 wrote:
I figured it out. I had to modify the script to include explicit paths to the various commands. I guess it couldn't find timeout or some of the other commands.

Anyone else on Verizon FIOS is welcome to steal the script. It can certainly be modified to search for other types of traffic as well.

Thanks to all who offered suggestions. I love this community.

Code:

#!/bin/sh

# set the variable below to your FIOS interface
IF=eth1
logger -t v6test "Starting daily scan for IPV6"
/opt/bin/timeout 5m /opt/sbin/tcpdump -ni ${IF} 'icmp6 && ip6[40] == 134' -c 10 >/tmp/${IF}_RAs.out
FSIZE=$(/opt/bin/stat /tmp/${IF}_RAs.out)
FSIZE2=$(echo $FSIZE | cut -c33-34)
echo $FSIZE2
if [ "$FSIZE2" -gt 1 ]; then
  logger -t v6test "RA packet detected on eth1 $0"
  cat /jffs/mail.txt | /opt/bin/msmtp -a gmail redacted@mydomain.com
fi
logger -t v6test "End scan for IPV6"

_________________
DD-WRT V3.0-r49626 std (08/03/22) on WRT3200ACM and flying...
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Sun Dec 12, 2021 13:11    Post subject: Reply with quote
IDK you could also use export=full/path and try that way.

In any case its solved and that's the only thing that matters.

take care.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Marvell MVEBU based Hardware (WRT1900AC etc.) 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