我试图编写一些文件分发脚本: 脚本接收文件/目录以var'filename'的形式分发,目标路径为'path',然后应该运行srv.list中列出的所有服务器,并将文件/ dir分配给每个服务器。另外还有那个在用户输入是dir而不是文件时使用的ropt。Python - 语法错误。 TypeError:无法连接'str'和'int'对象
#!/usr/bin/python
import os
dirList = os.listdir("./")
srvlist = os.system("cat srv.lst")
filename = raw_input("Please enter file/dir to distribute")
path = raw_input("Please enter destination path")
ropt =()
for d in dirList:
if os.path.isdir(d) == True:
ropt = "-r"
os.system("/usr/bin/scp " (ropt)"-- "(filename)" "(srvlist)":"(path)
else:
os.system("/usr/bin/scp "(filename)" "(srvlist)":"(path))
输出:
Please enter file/dir to distribute: 1.py
Please enter destination path: /root/
Traceback (most recent call last):
File "1.py", line 13, in ?
os.system("/usr/bin/scp "+filename+" "+srvlist+":"+path)
TypeError: cannot concatenate 'str' and 'int' objects
[[email protected] distribute]#
你有什么错误?你的hashbang(#!python)似乎不是正确的。 – 2013-04-21 14:47:50
通常,在将用户输入传递给shell命令之前不进行消毒是一个不好的主意。 – 2013-04-21 14:49:19
我问的问题,因为我试图学习,如果你来,至少写下我的问题,至少写下为什么。 – 2013-04-21 14:54:01