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

发布于 2024-11-03 21:10:08 字数 5469 浏览 1 评论 0原文

当我从交互式 shell 调用 telnet 连接到日间服务器时,它工作正常。但是,当从 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)                                 = ?

欢迎任何帮助。

When I call telnet to connect to daytime server from interactive shell, it works fine. However, when the same telnet call is issued from a shell script run by cron or some bash daemon process, it fails to yield any otput. I straced the both calls, and here they are:

Successful one:

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)                                 = ?

Unsuccessful one:

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)                                 = ?

Any help welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷血 2024-11-10 21:10:08

呃……管道或独立输入根本不是终端。再多的环境设置也无法解决这个问题。 TRWTF 正在从守护进程使用 telnet

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

Ermmm... a pipe or detached input is simply not a terminal. No amount of environment settings is going to fix that. TRWTF is using telnet from a daemon

Short story: use sockets to connect to the same port as what you (ab)use telnet for. This will greatly simplify your setup and also not require a terminal or subprocesses

顾挽 2024-11-10 21:10:08
ioctl(0, TIOCGWINSZ, 0xbe90a9cc)        = -1 ENOTTY (Inappropriate ioctl for device)

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

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

I think this is your problem. When cron executes, you don't have the same env vars and such that you do in a regular terminal. The above line is the first deviation the two outputs show and it looks like it setting/checking a terminal window size (WINSZ), presumably for the telnet session window. Maybe check the value of $TERM inside the cron script?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文