ディレクトリ内のすべてのファイルについて報告するスクリプトがあるため、ユーザーはそれらを消去する必要があります(実際のスーパーユーザーがいない、非常に管理の悪いクラスターです)。スクリプトを実行すると: OSError: [Errno 13] Permission denied: ' ls: : Permission denied I can't write the dir name (company policy) コードは:
#!/depot/Python-3.1.1/bin/python3.1
from stat import *
import stat
import sys
from collections import defaultdict
from pwd import getpwuid
import sys
sys.path.append('/remote/us01home15/ldagan/python')
import mailer
import os
import re
import glob
import subprocess
import pwd
def find_owner(file):
return pwd.getpwuid(os.stat(file)[stat.ST_UID]).pw_name
if (len(sys.argv) < 1):
sys.error('''Please input <runda number> <case number>''')
files_by_users=defaultdict(list)
runda_num="".join(sys.argv[1])
dir_basic='/berry/secure'
case_num="".join(sys.argv[2])
secure_dir="".join([dir_basic,"/"])
i=1
dirs=[]
runda_case_dir="".join([dir_basic,'/',runda_num,'/',case_num ])
while (os.path.exists(secure_dir)):
if (os.path.exists(runda_case_dir)):
dirs.append(runda_case_dir)
i+=1
secure_dir="".join([dir_basic,str(i)])
runda_dir="/".join([secure_dir,runda_num,case_num])
#now finding list of
manager_email='ldagan@synopsys.com zafrany@synopsys.com'
def bull (msg):
i=1
for dir in dirs:
for root,dirs,files in os.walk(dir,onerror=bull):
for file in files:
file_full_name=os.path.join(root,file)
files_by_users[find_owner(file_full_name)].append(file_full_name)
for username in files_by_users:
sendOffendingNotice(username, file_by+users[username], manager_email)
def sendOffendingNotice(username,filenames,managerEmail):
"""gets file name & manager Email
sends an Email to the manager for review. As there are no smtp
definitions, mailx shall be used"""
user_email=username+'@synopsys.com'
message="""The following files \n""" + """\n""".join(filenames) +"""\n""" + \
""" which belongs to user """ + username +""" does not meet the required names's SPEC\nPlease keep it under a directory which has a proper case/star name\n"""
message= """echo \"""" + message+ """" | mailx -s "Offending files" """ + managerEmail +" " #+user_email
process=subprocess.Popen(message,shell=True)
スクリプトは電子メールを送信しませんが、終了します。初心者を助けてくれてありがとう。