Ssh argument length: Difference between revisions
m (New page: On Solaris 10, you can create command up to about 1MB in length. <geshi lang="bash"> $ getconf ARG_MAX 1048320 </geshi> However, what is the max length of a command which you can execute...) |
mNo edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Locally you can figure out the maximum argument length on your host. This can be limited by the shell and/or the kernel, depending on the platform. For example, on Solaris 10 in bash, you can create command up to about 1MB in length. | |||
<geshi lang="bash"> | <geshi lang="bash"> | ||
Line 19: | Line 19: | ||
while [ $r -gt 0 ]; do | while [ $r -gt 0 ]; do | ||
printf "Checking length $mid \r" | printf "Checking length $mid \r" | ||
l=$(ssh $host printf "$(yes | base64 -w 0 | head -c$mid)" | wc -c) | # this command only works if you have base64 and GNU versions of head | ||
#l=$(ssh $host printf "$(yes | base64 -w 0 | head -c$mid)" | wc -c) | |||
# The follow command should work on older Solaris hosts - Thanks Alexis | |||
l=$(ssh $host printf "$(cat /dev/urandom | tr -cd 'a-f0-9' | dd count=1 bs=$mid)" | wc -c) | |||
if [ $l -eq $mid ]; then | if [ $l -eq $mid ]; then | ||
mid=$((mid+r)) | mid=$((mid+r)) | ||
Line 25: | Line 28: | ||
mid=$((mid-r)) | mid=$((mid-r)) | ||
fi | fi | ||
# slightly better / worse: r=$(awk "BEGIN{print int(($r/2)+0.5)}") | |||
r=$((r/2)) | r=$((r/2)) | ||
done | done | ||
Line 54: | Line 58: | ||
If you need more than is, one could pipe the command into stdin and then execute it, or create a script on the remote side and execute that script. | If you need more than is, one could pipe the command into stdin and then execute it, or create a script on the remote side and execute that script. | ||
If you default shell is csh, you will get output like | |||
<pre> | |||
$ ~/bin/check-sshlength.sh everest | |||
Received disconnect from 10.0.0.92: 2: Bad packet length 1000044. | |||
Received disconnect from 10.0.0.92: 2: Bad packet length 500044. | |||
Word too longth 250000 | |||
Word too longth 125000 | |||
Word too longth 62500 | |||
Word too longth 31250 | |||
Word too longth 15625 | |||
Word too longth 7813 | |||
Word too longth 3907 | |||
Word too longth 1954 | |||
Word too longth 1466 | |||
Word too longth 1222 | |||
Word too longth 1100 | |||
Word too longth 1039 | |||
Word too longth 1024 | |||
Word too longth 1020 | |||
Maximum ssh argument length between everest and everest is 1019 | |||
</pre> | |||
See | |||
* [http://www.grymoire.com/Unix/CshTop10.txt Top Ten Reasons not to use the C shell] | |||
* [http://www.in-ulm.de/~mascheck/various/argmax/ ARG_MAX, maximum length of arguments for a new process] | |||
[[Category:Solaris]] | [[Category:Solaris]] | ||
[[Category:Bash]] |
Latest revision as of 13:48, 10 May 2011
Locally you can figure out the maximum argument length on your host. This can be limited by the shell and/or the kernel, depending on the platform. For example, on Solaris 10 in bash, you can create command up to about 1MB in length.
<geshi lang="bash"> $ getconf ARG_MAX 1048320 </geshi>
However, what is the max length of a command which you can execute via ssh? To answer this, I wrote a basic script to test this.
<geshi lang="bash">
- !/bin/bash
- usage: <host> <arg size guess>
host=${1-localhost} mid=${2-1048320} r=$((mid/2))
while [ $r -gt 0 ]; do
printf "Checking length $mid \r" # this command only works if you have base64 and GNU versions of head #l=$(ssh $host printf "$(yes | base64 -w 0 | head -c$mid)" | wc -c) # The follow command should work on older Solaris hosts - Thanks Alexis l=$(ssh $host printf "$(cat /dev/urandom | tr -cd 'a-f0-9' | dd count=1 bs=$mid)" | wc -c) if [ $l -eq $mid ]; then mid=$((mid+r)) else mid=$((mid-r)) fi # slightly better / worse: r=$(awk "BEGIN{print int(($r/2)+0.5)}") r=$((r/2))
done
echo echo "Maximum ssh argument length between $(hostname) and $host is $mid" </geshi>
The results of the script look like:
~/bin/check-sshlength.sh everest Received disconnect from 10.0.0.92: 2: Bad packet length 1000044. Received disconnect from 10.0.0.92: 2: Bad packet length 500044. Received disconnect from 10.0.0.92: 2: Bad packet length 375036. Received disconnect from 10.0.0.92: 2: Bad packet length 312540. Received disconnect from 10.0.0.92: 2: Bad packet length 281292. Received disconnect from 10.0.0.92: 2: Bad packet length 265660. Received disconnect from 10.0.0.92: 2: Bad packet length 263708. Received disconnect from 10.0.0.92: 2: Bad packet length 262732. Received disconnect from 10.0.0.92: 2: Bad packet length 262252. Received disconnect from 10.0.0.92: 2: Bad packet length 262188. Received disconnect from 10.0.0.92: 2: Bad packet length 262156. Received disconnect from 10.0.0.92: 2: Bad packet length 262156. Maximum ssh argument length between everest and everest is 262111
This makes sense as this jives with the maximum packet length of an ssh session. http://www.free.lp.se/fish/rfc.txt
If you need more than is, one could pipe the command into stdin and then execute it, or create a script on the remote side and execute that script.
If you default shell is csh, you will get output like
$ ~/bin/check-sshlength.sh everest Received disconnect from 10.0.0.92: 2: Bad packet length 1000044. Received disconnect from 10.0.0.92: 2: Bad packet length 500044. Word too longth 250000 Word too longth 125000 Word too longth 62500 Word too longth 31250 Word too longth 15625 Word too longth 7813 Word too longth 3907 Word too longth 1954 Word too longth 1466 Word too longth 1222 Word too longth 1100 Word too longth 1039 Word too longth 1024 Word too longth 1020 Maximum ssh argument length between everest and everest is 1019
See