How to type commands more than 512 characters?

Hi,

I am trying to type in this command

S=$(uci get dhcp.lan.start); L=$(uci get dhcp.lan.limit); C=$(ip -o -f inet addr show br-lan | awk '{print $4}'); I=${C%/*}; M=${C#*/}; eval $(echo $I | awk -F. '{printf "a=%d;b=%d;c=%d;d=%d",$1,$2,$3,$4}'); N=$(( ((a<<24)+(b<<16)+(c<<8)+d) & (0xFFFFFFFF<<(32-M)&0xFFFFFF
FF) )); E=$((S+L-1)); ST=$(uci show dhcp | grep '@host\[.*\]\.ip=' | cut -d"'" -f2 | tr '\n' ' '); i=$E; while [ $i -ge $S ]; do X=$((N+i)); A=$(printf "%d.%d.%d.%d" $((X>>24&255)) $((X>>16&255)) $((X>>8&255)) $((X&255))); echo " $ST " dsf

but since it is more than 512 character it gets truncated when I paste it.

How can I increase the maximum command lenght from 512, so something more useful such as 65536 characters ?

thanks

And this command

C=$(ip -o -f inet addr show br-lan|awk '{print $4}');I=${C%/*};M=${C#*/};eval $(echo $I|awk -F. '{printf "a=%d;b=%d;c=%d;d=%d",$1,$2,$3,$4}');P=$((a<<24|b<<16|c<<8|d));K=$((0xFFFFFFFF<<32-M&0xFFFFFFFF));N=$((P&K));B=$((P|~K&0xFFFFFFFF));S=$(uci get dhcp.lan.start);L=$(uci get dhcp.lan.limit);DS=$((N+S));DE=$((N+S+L-1));T=$(uci show dhcp|awk '/@host\[.*\]\.ip=/{gsub(/.*=/,"");gsub(/\047/,"");print}'|tr '\n' '|');i=$((B-1));while [ $i -gt $N ];do [ $i -ge $DS ]&&[ $i -le $DE ]&&{i=$((i-1));continue;};A=$(printf "%d.%d.%d.%d" $((i>>24&255)) $((i>>16&255)) $((i>>8&255)) $((i&255)));echo "$T"|grep -q "$A"||{ping -c 1 -W 5 $A >/dev/null 2>&1||{echo $A;break;};};i=$((i-1));done

Ping every network address, starting from the last, excluding the broadcast address, excluding the dhcp range addresses, excluding the static ip leases and returns the first address which times out after a 5 second delay.

Save it as a shell script.

3 Likes

you could try installing and executing it in bash instead.

1 Like

In my case building a tmpfile script would be quite cumber some, and would require running many commands since you could add less than 512 character per command run.

It appears it is impossible to change the 512 character limit without recompiling ash with a different hardcoded value.

512 character is very stingy !!
Even DOS (well, cmd.exe at least) allows 8131 without issues (8191 if you really push it carefully)

So for now it appears the sane solution is

USER=root && apk add bash && sed -i "s|^${USER}:.*:/bin/ash$|${USER}:x:0:0:${USER}:/root:/bin/bash|" /etc/passwd

Kind of opposite activities?

you can pipe multi-line file as a parameter to a command.

busybox ash -c  << EOF
echo 0
echo 1
: fill to a megabyte if u like
echo 501

EOF

Just adding the reference for the 512 char limit:

Because line editing is enabled, it’s capped at 512. If line editing was not enabled, busybox would default to 1024.

5 Likes

@brada4
sorry, I was unclear and equated typing and pasting. In my actual case it neither paste nor type, the command is provided via an ssh client, further complicating the matter. I did not realize the implications at the time.

@frollic
While installing and replacing the shell with bash solved the prior issue. Unfortunately now some of the navigation keys have broken, namely home/end which is very annoying ! I will endeavour to find the solution to this extra paper cut. I wish ash could have its max command line length changed from configuration file !

@dave14305
Could this default value be increase to 8192 (or, gasp, 16384! ) ? Although I appreciate that if I were to run ash on a ESP32 it might actually work, the device I own with the smallest amount of ram is the TP-Link TL-WA901ND and even it comes with a luxurious 32MiB of RAM so I think it can afford this extravagance !

You could build it with whatever you like, but I don’t think it makes sense as a default for low-end devices, or the average user.

3 Likes

Isn't this 16384 bytes of memory only allocated when an interactive shell is running ? Wish for most router is basically never ?

I personally find this 512 character limit very constraining. I tried to minify my command as much as possible

For instance in this command

set "USER=root" & set "HOST=router.lan" & cmd /V:ON /C ssh -i "%USERPROFILE%\.ssh\%HOST%.private" -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL %USER%@%HOST% IP=$(C=$(ip -o -f inet addr show br-lan | awk '{print $4}'); I=${C%/*}; M=${C#*/}; eval $(echo $I | awk -F. '{printf "a=%d;b=%d;c=%d;d=%d",$1,$2,$3,$4}'); P=$((a<<24|b<<16|c<<8|d)); K=$((0xFFFFFFFF<<32-M&0xFFFFFFFF)); N=$((P&K)); B=$((P|~K&0xFFFFFFFF)); S=$(uci get dhcp.lan.start); L=$(uci get dhcp.lan.limit); DS=$((N+S)); DE=$((N+S+L-1)); T=$(uci show dhcp | awk '/@host\[.*\]\.ip=/{gsub(/.*=/,"");gsub(/\047/,"");print}' | tr '\n' '|'); i=$((B-1)); while [ $i -gt $N ]; do [ $i -ge $DS ] && [ $i -le $DE ] && { i=$((i-1)); continue; }; A=$(printf "%d.%d.%d.%d" $((i>>24&255)) $((i>>16&255)) $((i>>8&255)) $((i&255))); echo "$T" | grep -q "$A" || { ping -c 1 -W 5 $A >/dev/null 2>&1 || { echo $A; break; }; }; i=$((i-1)); done); uci set dhcp.deadgateway=tag; uci add_list dhcp.deadgateway.dhcp_option="3,$IP"; uci commit dhcp

Which means create a DHCP tag called "deadgateway" which sets dhcp option 3 to a value that is the highest value ip host address on the network, excluding the broadcast address, excluding any static lease, excluding the dhcp range which does not respond to a ping with a timeout of 5 second.

And yes, it does work properly with bash

It is not really just "a command". It is a full script...

1 Like

Looks a lot like AI slop. Ask your agent to compact its :poop:

It's a one liner awk script inside a oneliner ash inside a oneliner batch command but all that really matter is that it works and it's one line.

I tried to minify it further but this is as tight as I can make it.

The batch preamble is not including the 512 characters just the ash payload ....

set "USER=root" & set "HOST=router.lan" 

is for this part of the command

ssh -i "%USERPROFILE%\.ssh\%HOST%.private.openssh" -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL %USER%@%HOST%

I put it there because I always put my variables at the beginning