I know this is 15 years old, but it was the first result for setting ssh terminal width and it doesn't actually answer the question. Let me explain what the problem is and give a bunch of example data so you can see what the problem is.
On a BSD host in my network I ran
sudo hostname this-is-a-really-long-hostname-because-i-am-testing-something. So for a few minutes, that VM thinks it has an absurdly long hostname. Then on that VM, I run
sudo service netif restart. That causes the host to re-request its DHCP lease, sending this silly hostname to the DHCP server on my router.
Now, like the OP I am sending commands to my Mikrotik (model: RB4011iGS+, revision: r2, current-firmware: 7.10.1, routeros 7.14.3) authenticated using an SSH key.
If I login interactively with an SSH session from a terminal window that is wide on my screen, I can run:
/ip/dhcp-server/lease/print where address="172.30.2.28" and I see this:
Flags: D - DYNAMIC
Columns: ADDRESS, MAC-ADDRESS, HOST-NAME, SERVER
# ADDRESS MAC-ADDRESS HOST-NAME SERVER
0 D 172.30.2.28 6E:15:09:09:26:56 this-is-a-really-long-hostname-because-i-am-testing-something marmite
THIS IS THE OUTPUT I WANT. This is good. All i want to do is get this exact output non-interactively.
If I run
/ip/dhcp-server/lease/print file=test.txt where address="172.30.2.28" and then I look at the contents of test.txt, I see:
# 2024-12-07 10:26:42 by RouterOS 7.14.3
# software id = XXXX-XXXX
#
Flags: D - DYNAMIC
Columns: ADDRESS, MAC-ADDRESS
# ADDRESS MAC-ADDRESS
112 D 172.30.2.28 6E:15:09:09:26:56
The entire HOST-NAME column has been omitted. I assume this is because it is too wide for whatever line length the print command uses. If it's for some other reason, then what do I need to do to change it?
If I run
ssh gw '/ip/dhcp/lease/print where address="172.30.2.28"' to just get the ip leases output in a non-interactive way (the kind of thing one might put in a script), I get the same output:
Flags: D - DYNAMIC
Columns: ADDRESS, MAC-ADDRESS
# ADDRESS MAC-ADDRESS
17 D 172.30.2.28 6E:15:09:09:26:56
If I use the
brief option, as suggested in this thread, I still don't get the HOST-NAME column. If I use the
detail option, I get the full hostname, but now the output is in this multi-line stanza format that I have to parse. What I really want is the IP address and the hostname and nothing else. And I don't care about line length. This is 2024 and I don't have some DEC VT100 that physically limits the number of letters on the screen. What would be awesome is JSON format, but I'll take text that doesn't omit entire columns.
The
documentation on the command-line interface says that line width is controlled by parameters after the login name. That's really unusual, but whatever. It offers the following example: "
admin+c80w - will disable console colors and set terminal width to 80". So I try
ssh marmite+c80w@gw and indeed, I get an interactive SSH session and color is disabled as I expected. However, my actual terminal window is much wider than 80 characters and when I run the
/ip/dhcp/lease/print command, I get the full host-name column. The output is far wider than 80 characters. So the 'c' flag for disabling color seems to work, but the 80w part doesn't seem to have the effect I expect. Likewise running
ssh marmite+2000w@gw '/ip/dhcp/lease/print where address="172.30.2.28"' still gets me the output without the host-name column, even though I theoretically told it I was happy with 2000 character width. (I also tried some smaller values like 110w and 130w).
So how do I get the
/ip/dhcp/lease/print command to print really wide output when I use a non-interactive SSH connection to execute it?