I have a remote device where telnetd
daemon is running. I would like to execute a few sed
commands to update the /etc/securetty
file and add pts/0, pts/1...pts/n
to this file on this device through a telnet connection. I wrote the following python
function using telnetlib
to execute the sed
commands:
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)
The above produces the output as follows:
# 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
while the output I wanted was:
# 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
I believe that the sed
command itself is wrong. How can I get the desired output?
PS : I'm using poky linux
from yocto project
and my sed
version is mentioned as This is not GNU sed version 4.0
.