From: Peter E. <pe...@bo...> - 2004-05-27 16:11:30
|
I'm having the age-old problem tty issues where when I run the script from the command-line things work like they should. If it runs from the daemon it doesn't work right though the script itself seems to run. The client is bsdftps, er ftps from the command-line. [ Hey, for those that only know sermons and not gospel, point me to the FTPS.pm and I'll gladly use that then suffer through this drama. ] My relevant portions: use POSIX ":sys_wait_h"; use FileHandle; use IO::File; use IO::Select; use IO::Pty; use Carp; use Expect; $Expect::Log_Stdout=0; $self->{_exp} = new Expect; $self->{_exp}->raw_pty(1); $self->{_exp}->stty('raw'); $self->{_prompt} = 'ftps>'; $self->{_timeout} = 10; my @cmd = '/usr/bin/ftps'; push @cmd, '-e'; push @cmd, '-v'; push @cmd, '-P', $self->{_port}; push @cmd, '-d' if ($self->{_debug}); push @cmd, '-p' if ($self->{_passive}); push @cmd, '-n' if ($self->{_autologin}); push @cmd, $self->{'_host'}; my $c = join ' ', @cmd; VSI::RS::Results->new($ident, 0, '', '', 0)->logThis('debug', "STARTUP: $c") if ($DEBUG); close(STDOUT); open(STDOUT, '>/dev/null'); close(STDIN); close(STDERR); $self->{_exp}->log_file("/tmp/exp-$$", 'w'); #$self->{_exp}->slave->set_raw(); #$self->{_exp}->set_raw(); $self->{_exp}->spawn(@cmd) || return 0; $self->{_exp}->expect($self->{_timeout}, [ qr/Name /i, sub { my $self = shift; $self->send($user . "\n"); exp_continue; }], [ qr/Password:/i, sub { my $self = shift; $self->send($pass . "\n"); exp_continue; }], $self->{_prompt}); my $return = $self->{_exp}->before(); foreach my $line (split /\r?\n/, $return) { $self->message($line) if ($line =~ /^(\d+) /); } All of the above works to where it can connect and log in. So then I set to the directory with: my $cmd = "cd $dir\n"; $self->{_exp}->expect($self->{_timeout}, '', $self->{_exp}->send($cmd), $self->{_prompt}); my $return = $self->{_exp}->before(); foreach my $line (split /\r?\n/, $return) { $self->message($line) if ($line =~ /^(\d+) /); } But I never get back the junk I should after the command is issued. Oddly, my prompt matches. Assuming though that the 'cd' worked, I'm getting nothing back when I do a listing in the directory: my $cmd = "dir\n"; my @list; my @listing; $self->{_exp}->expect($self->{_timeout}, '', $self->{_exp}->send($cmd), $self->{_prompt}); my $return = $self->{_exp}->before(); foreach my $line (split /\r?\n/, $return) { my @fields = split /\s+/, $line; if ((scalar @fields) >= 9 && $line!~/^\d{3}/) { my $index = (scalar @list); $list[$index]{'perm'} = shift @fields; # perms shift @fields; # skip weird thing $list[$index]{'user'} = shift @fields; $list[$index]{'group'} = shift @fields; $list[$index]{'size'} = shift @fields; $list[$index]{'date'} = join ' ', (shift @fields, shift @fields, shift @fields); $list[$index]{'filename'} = join ' ', @fields; # push @listing, $list[$index]{'filename'}; $listing[$index] = $list[$index]{'filename'}; } else { $self->message($line) if ($line =~ /(\d+) /); } } return @listing; Again, if I run the same process without being invoked underneath (RH7.3): daemon --user genuser ... It all works swell. What [simple] detail am I missing? Many thanks, peter |