提问人:Christopher Calvani 提问时间:10/13/2021 更新时间:10/13/2021 访问量:1093
查找匹配的 ''' 时出现意外的 EOF:这是什么意思?
unexpected EOF while looking for matching `'': What does this mean?
问:
这些是我在运行add_user.py时从终端收到的错误消息
sh:-c:第 0 行:查找匹配的 ''' 时出现意外的 EOF
sh:-c:第 1 行:语法错误:文件意外结束
在网上阅读了一些后,我被引导相信这些错误是在我缺少匹配的括号或引号时抛出的?我已经多次查看了该文件,但由于已经过了几个小时,我可能只是直接查看错误。如果不是缺少引号或括号,请解释可能导致问题的原因,以便我修复它。感谢所有帮助过的人!
import csv
import os
filename = "/root/Downloads/linux_users.csv"
def create_username(aList):
if (len(aList) < 2):
print("INVALID RECORD")
else:
tokens = list(aList[2])
username = tokens[0].lower() + aList[1].lower()
return username
with open(filename) as f_handle:
csv_reader = csv.reader(f_handle)
next(csv_reader)
userList = []
groupList = []
recordCopy = []
rep = 0
tick = True
for record in csv_reader:
if (record[7] == ""):
record.remove(record[7])
for data in record:
if (data == ""):
print("ERROR: MISSING INFORMATION. USER ID: " + record[0] + " HAS NOT BEEN ADDED")
tick = False
if ((record[6] not in groupList) and (tick == True)):
groupList.append(record[6])
if (tick == True):
username = create_username(record)
if (username in userList):
username += str(rep)
rep += 1
userList.append(username)
recordCopy.append(record)
else:
tick = True
for group in groupList:
os.system("groupadd " + group)
print("GROUP: " + group + " HAS SUCCESSFULLY BEEN CREATED")
i = 0
for record in recordCopy:
if (record[5] == "ceo"):
os.system("adduser " + userList[i] + " -g " + record[6] +
" -d /home/" + record[5] + " -s /bin/csh -u " + record[0] + " -p password")
os.system("passwd -e " + userList[i])
else:
os.system("adduser " + userList[i] + " -g " + record[6] +
" -d /home/" + record[5] + " -s /bin/bash -u " + record[0] + " -p password")
os.system("passwd -e " + userList[i])
i += 1
print("USER: " + record[0] + " HAS SUCCESSFULLY BEEN ADDED")
答: 暂无答案
评论
os.system()
os.system()
subprocess.run()
shell=True
subprocess.run(["adduser", userList[i], "-g", record[6], "-d", f"/home/{record[5]}", "-s", "/bin/bash", "-u", record[0], "-p", "password"])
subprocess.run()
$(rm -rf ~)'$(rm -rf ~)'