- utils.header("messing with known_hosts (cleaning hostnames starting with 'test'")
- try:
- file1=open('/root/.ssh/known_hosts','r')
- file2=open('/root/.ssh/known_hosts_temp','w')
- while 1:
- txt = file1.readline()
- if txt=='':
- file1.close()
- file2.close()
- break
- if txt[0:4]!='test' :
- file2.write(txt)
-
-
- os.system('set -x ; mv -f /root/.ssh/known_hosts_temp /root/.ssh/known_hosts')
- except Exception, e:
- print str(e)
+ utils.header("Messing with known_hosts (cleaning hostnames starting with 'test'")
+ sed_command="sed -i -e '/^test[0-9]/d' /root/.ssh/known_hosts"
+ os.system("set -x ; " + sed_command)