Last active
April 2, 2018 16:34
-
-
Save dansherman/3203473400431fd00508fcb3fd242b93 to your computer and use it in GitHub Desktop.
Python script to check for files in users PATH that conflict or override with system binaries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import os | |
import glob | |
path_string = os.environ['PATH'] | |
paths = path_string.split(":") | |
system_paths = ['/usr/bin','/bin','/usr/sbin','/sbin'] | |
system_files = {} | |
# Build list of files in system path | |
for system_path in system_paths: | |
for file in glob.glob(os.path.join(system_path,'*')): | |
if os.path.basename(file) not in system_files.keys(): | |
system_files[os.path.basename(file)] = [] | |
system_files[os.path.basename(file)].append(file) | |
# Check user paths for conflicts with system paths | |
for path in paths: | |
if path in system_paths: | |
continue # skip system paths | |
else: | |
print("Checking non-system path: %s" % path) | |
for file in glob.glob(os.path.join(path,'*')): | |
if os.path.basename(file) in system_files.keys(): | |
print("Conflict! %s -VS- %s" % (file,system_files[os.path.basename(file)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment