Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 80x24).

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

share|improve this question
    
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:<br> <b> #we're running from cron or smth <br> $logger->debug("setting /dev/tty0 window size to 80x24:");</br> /bin/stty -F /dev/tty0 columns 80 rows 24;<br> open TTY0, "/dev/tty0" or die "Can't open /dev/tty0: $!";<br> </b> $session->slave->clone_winsize_from(*TTY0); –  Mad_Ady Aug 12 '09 at 8:40

3 Answers 3

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);

share|improve this answer

I found this post very useful as I ran into the same problem after migrating some Perl code away from using Net::Telnet to Expect (Expect has extremely useful debugging output in comparison).

However in my situation I had a /dev/tty0 that was pretty locked down (only root could read it) and I didn't want to change that:

crw--w----    1 root     tty        4,   0 Aug 30  2002 /dev/tty0

I looked at the Expect/IO::Pty/IO::Tty source and ended up hacking in the following - which essentially does the same thing (80 x 24) without needing to read from /dev/tty0.

use IO::Tty;
use IO::Tty::Constant;
my $winsize = pack('SSSS', 24, 80, 0, 0);
ioctl($exp->slave(), &IO::Tty::Constant::TIOCSWINSZ, $winsize);
share|improve this answer

In the start of the script:

set columns 80
set rows 24
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.