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 | |
| import psutil | |
| def Virtual_memory_usage(): | |
| #VIRTUAL MEMORY INFORMATION | |
| virtu_full_num = psutil.virtual_memory().percent | |
| virtnum_int = int(float(psutil.virtual_memory().percent)) | |
| print "VRT MEM USAGE: ", virtu_full_num | |
| #print "0----------------100%" ##from initial version of script |
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 | |
| import os | |
| import psutil | |
| import subprocess | |
| import time | |
| ''' | |
| if os.exists("/etc/redhat-release"): | |
| process = "httpd" | |
| else: |
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
| import psutil | |
| #Generate a list of logged users. | |
| users = psutil.users() | |
| #list of banned users | |
| banned_users = ['root','gmastrokostas', 'test', 'test1', 'test3'] | |
| #empty list to insert the logged users. | |
| logged_users = [] | |
| #Will used to insert the results between the banned_users and logged_users. | |
| #This will distinguish users who are in the banned list Vs those who are not. | |
| banned_logged_users = [] |
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
| src_dict = ("/etc/yum.repos.d/") #Specify base directory | |
| pattern = re.compile ('http\S+') #CPatter to search for | |
| for yum_files in os.listdir(src_dict): # obtain list of files in directory | |
| files = os.path.join(src_dict, yum_files) #join the full path with the names of the files. | |
| strng = open(files) #We need to open the files | |
| for lines in strng.readlines(): #We then need to read the files | |
| if re.search(pattern, lines): #If we find the pattern we are looking for | |
| print re.split(r'=', lines)[1] #We split using as a delimeter the = sign. | |
| #INSERT WHATEVER CODE YOU WANT |
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
| import os | |
| import re | |
| src_drct='/home/gmastrokostas/tmp' | |
| for files in os.listdir(src_drct): | |
| if files.endswith('.txt'): | |
| oldF = os.path.join(src_drct, files) | |
| #midF = re.split(r'\.', files)#This works too. |
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
| import os | |
| import re | |
| src_drct='/home/gmastrokostas/tmp' | |
| for files in os.listdir(src_drct): | |
| if files.endswith('.txt'): #Select all files with the .txt ext | |
| oldF = os.path.join(src_drct, files) #Join full path with files found | |
| midF = re.split(r'\_', files) #split files that contain underscore |
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
| import socket | |
| import subprocess | |
| import netifaces | |
| import csv | |
| import paramiko | |
| def checkPING(IP): | |
| try: | |
| ping = subprocess.check_output(['ping', '-c1', ip]) | |
| return "Host is UP" |
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 | |
| import humanize | |
| import os, sys | |
| from os.path import join,getsize | |
| import humanize | |
| import pwd | |
| def dir_list(): | |
| list = [] | |
| drct = raw_input(":Enter directory name. Use full path: ") |
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
| import os, sys | |
| from os.path import join,getsize | |
| import humanize | |
| import pwd | |
| import psutil | |
| pids = [int(pid) for pid in os.listdir('/proc') if pid.isdigit()] | |
| for elements in pids: | |
| p = psutil.Process(elements) | |
| proc_name = p.name() |
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 | |
| #The script searches in a specific location for files and it gets in POSIX the time of modification of all files. | |
| #It also creates a temp file (and write text in it) within the same directory (which gets deleted once the script exits) | |
| #This temp file is used to get today's modification date. Then all POSIX dates are converted into human readable format | |
| #and a comparison is done between the temp file and the files we are examining. If the files we are examining are | |
| #three months or older, then .... you can enter what ever custom action you want. | |
| import os.path | |
| import tempfile | |
| import datetime |
NewerOlder