MissingTwins
Regular Contributor
Model ac86u ax86u 386.3_2
I'm trying to run a IPv6 to IPv4 port forwarding script, but I'm running into problems that related to crontab.
When the script is run for the 1st time it producing these logs, because iptables rule and socat processes don't exist yet.
But when this script gets run for the 2nd time no log should be generated, because both iptables and socat processes should be existing. But it keeps telling me that
Even more interesting is when I did this and watched socat in the
The
If I do this
I have checked the
If I ran my script manully or with
What I am doing wrong? I have no idea.
I'm lso trying to keep the child process running even after the parent process get killed with
Tested the same script with crontab on RPI4B ubuntu 20.04, no problem at all. It must be something wrong with the cru, a bug?
I'm trying to run a IPv6 to IPv4 port forwarding script, but I'm running into problems that related to crontab.
cru a RdpIPv6Daemon "*/1 * * * * /jffs/scripts/rdp-ipv6-mapping.sh"
When the script is run for the 1st time it producing these logs, because iptables rule and socat processes don't exist yet.
Bash:
Oct 31 02:59:00 rdp-ipv6-mapping.sh: Process not found socat TCP6-LISTEN:11111,fork TCP4:192.168.5.5:3389
Oct 31 02:59:03 rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 02:59:03 rdp-ipv6-mapping.sh: Success ip6tables -I INPUT -i ppp+ -p tcp --dport 11111 -j ACCEPT
Oct 31 02:59:03 rdp-ipv6-mapping.sh: Success ip6tables -I INPUT -i ppp+ -p udp --dport 11111 -j ACCEPT
Oct 31 02:59:03 rdp-ipv6-mapping.sh: Success ip6tables -I INPUT -i eth+ -p tcp --dport 11111 -j ACCEPT
Oct 31 02:59:03 rdp-ipv6-mapping.sh: Success ip6tables -I INPUT -i eth+ -p udp --dport 11111 -j ACCEPT
But when this script gets run for the 2nd time no log should be generated, because both iptables and socat processes should be existing. But it keeps telling me that
socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
doesn't exist every minute.
Bash:
Oct 31 01:23:01 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat TCP6-LISTEN:11111,fork TCP4:192.168.5.5:3389
Oct 31 01:23:01 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:24:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:25:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:26:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:27:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:28:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:29:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:30:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:31:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:32:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:33:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:34:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:35:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:36:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:37:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Oct 31 01:38:00 RT-AX86U-14F8-9B47D4C-C rdp-ipv6-mapping.sh: Process not found socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
Even more interesting is when I did this and watched socat in the
htop
, the log was still showing socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
didn't exist.
Bash:
socat TCP6-LISTEN:11111,fork TCP4:192.168.5.5:3389 &
socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389 &
cru a RdpIPv6Daemon "*/1 * * * * /jffs/scripts/rdp-ipv6-mapping.sh"
The
if [ $? != 0 ]; then
in the 2nd call of psCHK()
will always be true, even I have changed it into if [ -z "$RE" ]; then
it is still testing true.If I do this
echo "$PS_LIST" > /tmp/ps_list_`sed 's/[. ].*//' /proc/uptime`.txt
in psCHK()
only one /tmp/ps_list_xxxx.txt
will be generated every time, should be two.I have checked the
/tmp/ps_list_xxxx.txt` with `cat /tmp/ps_list_xxxx.txt | grep -i "socat" | grep -v grep
, socat
was in the ps list.
Bash:
15673 router 2544 S socat TCP6-LISTEN:11111,fork TCP4:192.168.5.5:3389
15690 router 2544 S socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389
while true; do /jffs/scripts/rdp-ipv6-mapping.sh ; sleep 5; done
for testing, it was functioning normally as expected.What I am doing wrong? I have no idea.
I'm lso trying to keep the child process running even after the parent process get killed with
( $CMD_STR & )
, but it doesn't work.
Bash:
#!/bin/bash
# Log Tag
LOG_TAG=`basename "$0"`
echo "LOG_TAG=$LOG_TAG"
# -----------------------------------------
# Example : sysLOG "We have a problem!" error
# Argu : $1 logs
# $2 error/notice/warning
# Input : None
# Return : None
function sysLOG() {
echo "$1" | tee /dev/tty | tr -d '\n' | logger -t $LOG_TAG -p user.$2;
}
# -----------------------------------------
# Example : psCHK "socat TCP6-LISTEN:11111,fork TCP4:192.168.5.5:3389"
# Argu : $1 command
# Input : None
# Return : None
function psCHK() {
local PS_CMD PS_LIST CMD_STR
CMD_STR=$1
ps aux &>/dev/null
[ $? != 0 ] && PS_CMD="ps" || PS_CMD="ps aux"
PS_LIST=$( $PS_CMD 2>&1 )
#echo "$PS_LIST" > /tmp/ps_list_`sed 's/[. ].*//' /proc/uptime`.txt
RE=$( echo -n "$PS_LIST" | grep -Fi "$CMD_STR" | grep -v grep )
#echo -n "$PS_LIST" | awk '$0 ~ /awk/{next} $0 ~ /'"$CMD_STR"'/{ print $0; err=0; exit} BEGIN{err=1} END{exit err}'
#=========================PROBLEM IS HERE=====================
#if [ $? != 0 ]; then
if [ -z "$RE" ]; then
sysLOG "Process not found $CMD_STR" warning
( $CMD_STR & )
sleep 1;
# PS_LIST=$( $PS_CMD 2>&1 )
# echo -n "$PS_LIST" | grep -Fi "$CMD_STR" | grep -v grep
# [ $? != 0 ] && sysLOG "Launch Failed $CMD_STR" error || sysLOG "Started $CMD_STR" notice
fi
}
# -----------------------------------------
# Example : ip6tablesINS "INPUT -i ppp+ -p tcp --dport 11111 -j ACCEPT"
# Argu : $1 ip6tables-rules
# Input : None
# Return : None
function ip6tablesINS() {
local reRAW RECODE
reRAW=$( ip6tables -C $1 2>&1 )
RECODE=$?
reRAW=$( echo -n "$reRAW" | head -n 1 )
# echo "=$RECODE |$1 | RE="$reRAW
if [ $RECODE -ge 2 ]; then
sysLOG "ip6tables -I $1 Err=$reRAW" error
elif [ $RECODE -eq 1 ]; then
ip6tables -I $1
[ $? != 0 ] && sysLOG "Error ip6tables -I $1" error || sysLOG "Success ip6tables -I $1" notice
fi
}
# Redirect TCP/UDP IPv6 11111 to IPv4 192.168.5.5: 3389
psCHK "socat TCP6-LISTEN:11111,fork TCP4:192.168.5.5:3389"
psCHK "socat UDP6-RECVFROM:11111,fork UDP4-SENDTO:192.168.5.5:3389"
# ip6tables
ip6tablesINS "INPUT -i ppp+ -p tcp --dport 11111 -j ACCEPT"
ip6tablesINS "INPUT -i ppp+ -p udp --dport 11111 -j ACCEPT"
ip6tablesINS "INPUT -i eth+ -p tcp --dport 11111 -j ACCEPT"
ip6tablesINS "INPUT -i eth+ -p udp --dport 11111 -j ACCEPT"
Tested the same script with crontab on RPI4B ubuntu 20.04, no problem at all. It must be something wrong with the cru, a bug?
Last edited: