#!/usr/bin/env python
#coding:utf8
from ConfigParser import ConfigParser
import telnetlib
config=ConfigParser()
config.read('telnet.config')
username = config.get('remote','username')
password = config.get('remote','password')
host = config.get('remote','ip')
finish = ':~$ '
tn = telnetlib.Telnet(host)
#每次做一个执行结束的判断':~$'
tn.read_until('login: ')
tn.write(username + '\n')
tn.read_until('Password: ')
tn.write(password + '\n')
#执行命令创建一个用户名同名的文件夹
tn.read_until(finish)
tn.write('mkdir %s\n'%username)
tn.read_until(finish)
tn.close()
telnet.config
[remote]
ip=127.0.0.1
username=username
password=password