Override screen size in linux telnet

telnet

Here's my predicament. I'm developing a perl telnet script that uses Expect to spawn a new telnet process and feed data (non-interactively) into it.

Everything works fine when I call the script from a terminal – however, if I start the script from cron I am unable to login to the remote device because the Window size negociation fails – as my client sends a window size of 0x0 (instead of 80×24).

Apparently telnet gets this window size from its master PTY – which isn't a TTY if it's called from cron. Most likely telnet is getting these settings using ioctl or some similar mechanism, because trying to override these settings by environment variables failed (ROWS=200 COLUMNS=80 telnet test).

I ran stty from cron and redirected the output to a file. Problem is stty complains when it's run from cron: /bin/stty: standard input: Invalid argument

Do you know any way to:
1) override the number of rows/columns telnet sends to the remote device
2) start a tty and start telnet inside that tty (from cron)

Thanks

Best Answer

update - I managed to solve my problem by using a workaround. The expect module has a function which copies the size of a TTY to the current "TTY" in which telnet runs. Problem was the default TTY was STDIN - which has no dimensions when run from cron. I forced it to get its dimensions from /dev/tty0 instead:

#we're running from cron or smth
$logger->debug("setting /dev/tty0 window size to 80x24:");
`/bin/stty -F /dev/tty0 columns 80 rows 24`;
open TTY0, "/dev/tty0" or die "Can't open /dev/tty0: $!";
$session->slave->clone_winsize_from(*TTY0);