python执行shell命令批量修改coremail系统用户信息
.知识
objFile=open("filename", 'rw')
line=objFile. readline()
objFile.close()
urllib.urlencode({'a':1, 'b':2,'c':3})
os.system("cmd")
str.split(separator_char)
len(line)
str.strip(char)
.mail_list.txt
"11" "123456" "tom" "abc@xx.com"
"19" "123456" "tom1" "abcd@xx.com"
"20" "123456789" "tom2" "abcde@xx.com"
"18" "123410" "tom3" "abcdef@xx.com"
"13" "123456" "tom4" "abcdefg@xx.com"
"11" "123456" "tom5" "abcdefgh@xx.com"
"17" "123456" "tom6" "abcdefghi@xx.com"
"15" "pstoto" "tom7" "abcdefghij@xx.com"
.[root@localhost script]# cat alteruser_bat.py
#!/usr/bin/python
import urllib;import os;
try:
f=open("mail_list.txt", "r");
while True:
line=f.readline();
if len(line) == 0:
break;
arr=line.strip().split(' ');
cmd="./alteruser 172.16.0.223 6195 "+arr[3].strip('"')+" \""+urllib.urlencode({'password': arr[1].strip('"'), 'org_unit_id': arr[0].strip('"'),'True_name': arr[2].strip('"') })+"\"";
print cmd
os.system(cmd);
finally:
f.close()
#end of script