我正在尝试编写一些文件分发脚本:该脚本接收要分发为 var 'filename' 的文件/目录,目标路径为 'path',然后应该运行 srv.list 中列出的所有服务器并 scp 文件/他们每个人的目录。此外,如果用户输入是目录而不是文件,则使用 ropt。
#!/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
[root@g1-lon distribute]#