O Telnet não é executado corretamente quando executado no processo do daemon

1

Quando eu chamo o telnet para conectar ao servidor diurno do shell interativo, ele funciona bem. No entanto, quando a mesma chamada de telnet é emitida a partir de um script de shell executado pelo cron ou por algum processo do daemon do bash, ele não produz qualquer saída. Eu segurei as duas chamadas, e aqui estão elas:

Sucesso:

execve("/usr/bin/telnet", ["telnet", "192.168.0.11", "13"], [/* 24 vars */]) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40005000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=3128, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
mmap2(NULL, 3128, PROT_READ, MAP_SHARED, 3, 0) = 0x40006000
close(3)                                = 0
stat("/etc/ld.so.preload", 0xbea5d8d4)  = -1 ENOENT (No such file or directory)
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=324423, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40007000
read(3, "7ELF
execve("/usr/bin/telnet", ["/usr/bin/telnet", "192.168.0.11", "13"], [/* 22 vars */]) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40005000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=3128, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
mmap2(NULL, 3128, PROT_READ, MAP_SHARED, 3, 0) = 0x40006000
close(3)                                = 0
stat("/etc/ld.so.preload", 0xbe90a8f4)  = -1 ENOENT (No such file or directory)
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=324423, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40007000
read(3, "7ELF
execve("/usr/bin/telnet", ["telnet", "192.168.0.11", "13"], [/* 24 vars */]) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40005000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=3128, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
mmap2(NULL, 3128, PROT_READ, MAP_SHARED, 3, 0) = 0x40006000
close(3)                                = 0
stat("/etc/ld.so.preload", 0xbea5d8d4)  = -1 ENOENT (No such file or directory)
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=324423, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40007000
read(3, "7ELF
execve("/usr/bin/telnet", ["/usr/bin/telnet", "192.168.0.11", "13"], [/* 22 vars */]) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40005000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=3128, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
mmap2(NULL, 3128, PROT_READ, MAP_SHARED, 3, 0) = 0x40006000
close(3)                                = 0
stat("/etc/ld.so.preload", 0xbe90a8f4)  = -1 ENOENT (No such file or directory)
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=324423, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40007000
read(3, "7ELF%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%(%pre%%pre%%pre%%pre%03%pre%%pre%04%pre%%pre%%pre%%pre%"..., 4096) = 4096
mmap2(NULL, 376832, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4000e000
mmap2(0x4000e000, 319264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x4000e000
mmap2(0x40064000, 4935, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x4e) = 0x40064000
mmap2(0x40066000, 14712, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40066000
close(3)                                = 0
munmap(0x40007000, 4096)                = 0
munmap(0x40006000, 3128)                = 0
stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=20486, ...}) = 0
mprotect(0x40064000, 4096, PROT_READ)   = 0
mprotect(0x4000c000, 4096, PROT_READ)   = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a714) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a714) = -1 ENOTTY (Inappropriate ioctl for device)
getuid32()                              = 0
ioctl(0, TIOCGWINSZ, 0xbe90a9cc)        = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a9b4) = -1 ENOTTY (Inappropriate ioctl for device)
brk(0)                                  = 0x91000
brk(0x92000)                            = 0x92000
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(13), sin_addr=inet_addr("192.168.0.11")}, 16) = 0
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
rt_sigaction(SIGINT, {0x667c0, [INT], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0
poll([{fd=0, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 2 ([{fd=0, revents=POLLIN}, {fd=3, revents=POLLIN}])
read(0, ""..., 128)                     = 0
exit(0)                                 = ?
%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%(%pre%%pre%%pre%%pre%03%pre%%pre%04%pre%%pre%%pre%%pre%"..., 4096) = 4096 mmap2(NULL, 376832, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4000e000 mmap2(0x4000e000, 319264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x4000e000 mmap2(0x40064000, 4935, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x4e) = 0x40064000 mmap2(0x40066000, 14712, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40066000 close(3) = 0 munmap(0x40007000, 4096) = 0 munmap(0x40006000, 3128) = 0 stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=20486, ...}) = 0 mprotect(0x40064000, 4096, PROT_READ) = 0 mprotect(0x4000c000, 4096, PROT_READ) = 0 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 getuid32() = 0 ioctl(0, TIOCGWINSZ, {ws_row=55, ws_col=203, ws_xpixel=0, ws_ypixel=0}) = 0 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 brk(0) = 0x91000 brk(0x92000) = 0x92000 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(13), sin_addr=inet_addr("192.168.0.11")}, 16) = 0 setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0 rt_sigaction(SIGINT, {0x667c0, [INT], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0 poll([{fd=0, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}]) read(3, "Wed Apr 27 11:42:10 2011\r\n"..., 128) = 26 write(1, "Wed Apr 27 11:42:10 2011\r\n"..., 26) = 26 poll([{fd=0, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}]) read(3, ""..., 128) = 0 write(1, "Connection closed by foreign host"..., 35) = 35 ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0 exit(1) = ?
%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%(%pre%%pre%%pre%%pre%03%pre%%pre%04%pre%%pre%%pre%%pre%"..., 4096) = 4096 mmap2(NULL, 376832, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4000e000 mmap2(0x4000e000, 319264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x4000e000 mmap2(0x40064000, 4935, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x4e) = 0x40064000 mmap2(0x40066000, 14712, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40066000 close(3) = 0 munmap(0x40007000, 4096) = 0 munmap(0x40006000, 3128) = 0 stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=20486, ...}) = 0 mprotect(0x40064000, 4096, PROT_READ) = 0 mprotect(0x4000c000, 4096, PROT_READ) = 0 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a714) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a714) = -1 ENOTTY (Inappropriate ioctl for device) getuid32() = 0 ioctl(0, TIOCGWINSZ, 0xbe90a9cc) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a9b4) = -1 ENOTTY (Inappropriate ioctl for device) brk(0) = 0x91000 brk(0x92000) = 0x92000 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(13), sin_addr=inet_addr("192.168.0.11")}, 16) = 0 setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0 rt_sigaction(SIGINT, {0x667c0, [INT], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0 poll([{fd=0, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 2 ([{fd=0, revents=POLLIN}, {fd=3, revents=POLLIN}]) read(0, ""..., 128) = 0 exit(0) = ?
%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%(%pre%%pre%%pre%%pre%03%pre%%pre%04%pre%%pre%%pre%%pre%"..., 4096) = 4096 mmap2(NULL, 376832, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4000e000 mmap2(0x4000e000, 319264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x4000e000 mmap2(0x40064000, 4935, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x4e) = 0x40064000 mmap2(0x40066000, 14712, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40066000 close(3) = 0 munmap(0x40007000, 4096) = 0 munmap(0x40006000, 3128) = 0 stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=20486, ...}) = 0 mprotect(0x40064000, 4096, PROT_READ) = 0 mprotect(0x4000c000, 4096, PROT_READ) = 0 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 getuid32() = 0 ioctl(0, TIOCGWINSZ, {ws_row=55, ws_col=203, ws_xpixel=0, ws_ypixel=0}) = 0 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 brk(0) = 0x91000 brk(0x92000) = 0x92000 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(13), sin_addr=inet_addr("192.168.0.11")}, 16) = 0 setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0 rt_sigaction(SIGINT, {0x667c0, [INT], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0 poll([{fd=0, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}]) read(3, "Wed Apr 27 11:42:10 2011\r\n"..., 128) = 26 write(1, "Wed Apr 27 11:42:10 2011\r\n"..., 26) = 26 poll([{fd=0, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}]) read(3, ""..., 128) = 0 write(1, "Connection closed by foreign host"..., 35) = 35 ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0 exit(1) = ?

Sem sucesso:

%pre%

Qualquer ajuda é bem-vinda.

    
por Damir 27.04.2011 / 11:56

1 resposta

1

ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a714) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbe90a714) = -1 ENOTTY (Inappropriate ioctl for device)

Tentando fazer um ioctl em STDIN ou STDOUT quando eles não existem (ou são redirecionados como quando executados como um daemon) para que os detalhes do terminal (TCGETS) não funcionem.

Você precisaria usar algo diferente de telnet, como socat ou nc , ou escrever seu próprio programa para fazer isso em alguma linguagem com suporte a soquete (C, Perl, PHP, etc.).

Você pode se conectar a servidores TCP simples no bash:

# bash accepts symbolic service (port) names according to /etc/services
# (of course you can use "/dev/tcp/$server/13" too)
read -r line <"/dev/tcp/$server/daytime"
echo "Today is $line"

Para protocolos mais complexos que o dia, você pode usar exec {fd}<>"/dev/tcp/$host/$port" e usar o $fd como um descritor de arquivo comum: read foo <&$fd , echo bar >&$fd , fechar com exec {fd}>&- .

    
por 27.04.2011 / 12:23