[Solved] Logger inserts an additional space after a variable when in an script

I created a custom script for reporting measured Internet speed on 19.07.3 to an external server. The line in question is:

logger "The measured speed is: DL="$measured_dl"Kbps and UL="$measured_ul"Kbps."

When run by CLI works perfectly, i.e.
router: The measured speed is: DL=abcdKbps and UL=wxyzKbps.
but when run in the ash script, inserts an unwanted blank_space between the variables and the rest of the text. i.e.
router: The measured speed is: DL=abcd Kbps and UL=wxyz Kbps.

How can I get rid of the extra blank_space?

logger "The measured speed is: DL=\"$measured_dl\"Kbps and UL=\"$measured_ul\"Kbps."

or the space is in your variable

1 Like

Thanks @anon50098793 for leading me in the right direction. Actually, the space was not in my variables, and what you suggested insert double_quotes before and after the variables:
image
But, after fiddling with it for a little bit, I came to an scape sequence that works from the CLI:
logger The measured speed is: DL=$measured_dl\Kbps and UL=$measured_ul\Kbps.
image
EDIT: but still don't work for the script.

1 Like

Nevermind: I wrote too quickly: after running the actual script with the scape codes \, it still inserts the blank space between the variables and the Kpbs.
So the issue remains open.

hmmm... looks like some whacky shell IFS or something... works for me;

#################### cat loggertest.sh 
measured_dl=100
measured_ul=200
logger "The measured speed is: DL="$measured_dl"Kbps and UL="$measured_ul"Kbps."
logread | tail -n1

########[root@rpi-dca6325 /usbstick 45°]# ./loggertest.sh 
user.notice root: The measured speed is: DL=100Kbps and UL=200Kbps.

i'm guessing your getting those variables from some commands output / sysfs etc. and you'll likely need to use sed/tr to strip the "non-visible" ammendums.

But you are doing this on your local router dir, right? I'm using an external log server.
I've done the same in dd-wrt and works perfectly for their busybox bash. I'm still fighting with my OpenWrt busybox ash. From my OpenWrt CLI, works fine, only fails when I run it from my crontab script.

1 Like

just tested from my cron also ok

What bugs me, is it runs OK from CLI to the free papertrailapp log server, but not when run from the script.
In fact, with dd-wrt I haven't needed to scape the characters.

put this in your script

echo -e -n $measured_dl | hexdump -C >> /tmp/varcheck
echo -e -n $measured_ul | hexdump -C >> /tmp/varcheck

I ran the script manually. Here:

root@Router:/tmp# ls -l varcheck*
-rw-r--r--    1 root     root           153 Jul  4 18:54 varcheck?
root@Router:/tmp# cat varcheck?
00000000  38 36 36 34 0d                                    |8664.|
00000005
00000000  31 37 30 0d                                       |170.|
00000004

1 Like

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

Wait, please not so fast. I calculated the variable as:
measured_dl=$((received_2-received_1)*8/time/1000)
How the 0D got there I don't know, but how can I rephrase my equation, please?

as I said the problem is not with the calculation, logger or cron.

measured_ul=$(echo $measured_ul | tr -d '\r')

Actually, there was no need to do any other change. I found somehow my Notepad++ was causing the error, as I edited the script directly on the router and now it works fine. In fact, my original script should have worked as intended.

Anyways, thanks for your support. I will mark this thread as solved.

1 Like

you're welcome :orangutan:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.