• No products in the cart.

DevOps on AWS – Python Scripts 10 : File Permissions


import stat, sys, os, string, commands

#Getting search pattern from user and assigning it to a list

 #run a ‘find’ command and assign results to a variable
pattern = raw_input(“Enter the file pattern to search for:n”)
commandString = “find ” + pattern
commandOutput = commands.getoutput(commandString)
findResults = string.split(commandOutput, “n”)

#output find results, along with permissions
print “Files:”
print commandOutput
print “================================”
for file in findResults:
     print “nPermissions for file “, file, “:”
     for level in “USR”, “GRP”, “OTH”:
           for perm in “R”, “W”, “X”:
                    if mode & getattr(stat,”S_I”+perm+level):
                           print level, ” has “, perm, ” permission”
                           print level, ” does NOT have “, perm, ” permission”
#print “There was a problem – check the message above”
February 22, 2021

0 responses on "DevOps on AWS - Python Scripts 10 : File Permissions"

    Leave a Message

    All rights reserved.
    error: Alert: Content is protected !!