从守护程序进程运行时,Telnet无法正常运行

时间:2011-04-27 09:57:41

标签: bash cron telnet

当我调用telnet从交互式shell连接到日间服务器时,它工作正常。但是,当从cron或某个bash守护程序进程运行的shell脚本发出相同的telnet调用时,它无法产生任何输出。我把这两个电话都拉了过来,他们在这里:

成功的一个:

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, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\320\253\0\0004\0\0\0\0"..., 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)                                 = ?

不成功的一个:

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, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\320\253\0\0004\0\0\0\0"..., 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)                                 = ?

欢迎任何帮助。

2 个答案:

答案 0 :(得分:3)

嗯...管道或分离输入只是终端。没有多少环境设置可以解决这个问题。 TRWTF正在使用来自守护进程的telnet

简短的故事:使用套接字连接到您(ab)使用telnet的同一端口。这将大大简化您的设置,也不需要终端或子流程

答案 1 :(得分:0)

ioctl(0, TIOCGWINSZ, 0xbe90a9cc)        = -1 ENOTTY (Inappropriate ioctl for device)

我认为这是你的问题。执行cron时,您没有相同的环境变量,而是在常规终端中执行此操作。上面的行是两个输出显示的第一个偏差,看起来它设置/检查终端窗口大小(WINSZ),大概是telnet会话窗口。也许在$TERM脚本中查看cron的值?