我有一个运行telnetd
守护程序的远程设备。我想执行一些sed
命令来更新/etc/securetty
文件,并通过telnet连接将pts/0, pts/1...pts/n
添加到此设备上的此文件中。我使用python
编写了以下telnetlib
函数来执行sed
命令:
def add_terminals(self):
print "Adding enough terminals for telnet...."
self.telnet.write("sed -i '/pts\/[0-9]/d' /etc/securetty")
self.telnet.write("\n")
time.sleep(1)
self.telnet.write("sed -i '$a \ ' /etc/securetty")
self.telnet.write("\n")
time.sleep(1)
self.telnet.write("sed -i '$a \# Local X displays added by me' /etc/securetty")
self.telnet.write("\n")
time.sleep(1)
self.telnet.write("sed -i '$a pts/0\\npts/1\\npts/2\\npts/3\\npts/4\\npts/5\\npts/6\\npts/7\\npts/8\\npts/9' /etc/securetty")
self.telnet.write("\n")
time.sleep(1)
以上产生如下输出:
# Local X displays added by me
pts/0\npts/1\npts/2\npts/3\npts/4\npts/5\npts/6\npts/7\npts/8\npts/9
虽然我想要的输出是:
# Local X displays added by me
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
我认为sed
命令本身是错误的。如何获得所需的输出?
PS:我使用的是来自poky linux
的{{1}},我的yocto project
版本被称为sed
。