求靠谱点的获取ttyshell的方法,最好是通过c或者perl的。

2012-06-22 18:25:07 7 4787
Linux目前已知的获取ttyshell的方法,一般有两种。

一是通过python:

python -c 'import pty; pty.spawn("/bin/sh")'

但是目标机器是64位系统,提示错误:

Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "/usr/lib64/python2.4/pty.py", line 153, in spawn
    pid, master_fd = fork()
  File "/usr/lib64/python2.4/pty.py", line 107, in fork
    master_fd, slave_fd = openpty()
  File "/usr/lib64/python2.4/pty.py", line 29, in openpty
    master_fd, slave_name = _open_terminal()
  File "/usr/lib64/python2.4/pty.py", line 70, in _open_terminal
    raise os.error, 'out of pty devices'
OSError: out of pty devices

二是通过shell脚本:

#!/usr/bin/expect
# Spawn a shell, then allow the user to interact with it.
# The new shell will have a good enough TTY to run tools like ssh, su and login
spawn sh
interact

但是expect不存在。

求其他方法。

关于作者

godblack484篇文章1190篇回复T00ls认证专家。

一个高尚的人,一个纯粹的人,一个有道德的人,一个脱离了低级趣味的人,一个有益于人民的人。

评论7次

要评论?请先  登录  或  注册