How to use log_reboot method in autotest

Best Python code snippet using autotest_python

MoonLight_Forensic.py

Source:MoonLight_Forensic.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: latin-1 -*-3# -*- coding: ascii -*-4# This Python file uses the following encoding: utf-85import os, sys6import time7def prRed(skk): print("\033[91m {}\033[00m" .format(skk))8def prGreen(skk): print("\033[92m {}\033[00m" .format(skk))9def prYellow(skk): print("\033[93m {}\033[00m" .format(skk))10def prLightPurple(skk): print("\033[94m {}\033[00m" .format(skk))11def prPurple(skk): print("\033[95m {}\033[00m" .format(skk))12def prCyan(skk): print("\033[96m {}\033[00m" .format(skk))13def prLightGray(skk): print("\033[97m {}\033[00m" .format(skk))14def prBlack(skk): print("\033[98m {}\033[00m" .format(skk))15prCyan('''16 _ ___ 17 | | / _ \ 18 _ __ ___ ___ __ __ | |_ __ __ | | | -|19 | '_ ` _ \ / _ \ \ \ /\ / / | __| \ \ /\ / / | | |----|20 | | | | | | | __/ \ V V / | |_ \ V V / | |_| --|21 |_| |_| |_| \___| \_/\_/ \__| \_/\_/ \___/ 22 23 24 _ 25 //\lperen |U|gurlu26 `-' 27 28''' )29 30 31prRed('''''''''''''''32 Linux Compromise Assessment33 * * * * * * * 34 * * ****** * * 35 ** * ** ** *36 * 37 * ** ** 38 * * *39 * * * * 40 * * * ** 41 * * 42 * * 43 44 * * * 45''''''''''''''')46prGreen(''' Scanning In Progress......47''')48time.sleep(4.0)49prRed('''50Operating System Information:51''')52def scan1():53 op_system = os.system('cat' + ' ' + '/etc/os-release')54 print(op_system) 55 prRed('''56 57 58It Is The File Where Connections to The System and Authentication Are Saved:59 ''')60def scan3():61 cd1 = os.system('cd' + ' ' + '/root/')62 63def scan2():64 log_in = os.system('cat' + ' ' + '/var/log/auth.log')65 print(log_in)66 prRed('''67 68 69Provides System Status, System Reboot Time and User Login Information:70 ''')71 72 73 74def scan4():75 cd2 = os.system('cd' + ' ' + '/root/')76 77def scan5():78 log_reboot = os.system('last' + ' ' + '-f' + ' ' + '/var/log/wtmp')79 print(log_reboot)80 prRed('''81 82 83Log of Failed Login Attempts:84 ''')85def scan6():86 cd3 = os.system('cd' + ' ' + '/root/')87 88def scan7():89 log_off = os.system('last' + ' ' + '-f' + ' ' + '/var/log/btmp')90 print(log_off)91 prRed('''92 93 94You Can Find Out If Any Suspicious Account Has Been Created And What Commands A User Can Run With Privilege Permission:95 ''')96def scan8():97 cd4 = os.system('cd' + ' ' + '/root/')98 99def scan9():100 users = os.system('cat' + ' ' + '/etc/passwd')101 print(users)102 prGreen(''' Scanning In Progress......103''')104 sudo_users = os.system('cat' + ' ' + '/etc/sudoers')105 print(sudo_users)106 prRed('''107 108 109It's a Log Of All Runs With Sudo:110 ''')111def scan10():112 cd5 = os.system('cd' + ' ' + '/root/')113 114def scan11():115 sudo_run = os.system('strings' + ' ' + '/var/log/auth.log*' + ' ' + '|' + ' ' + 'grep' + ' ' + '-i' + ' ' + 'COMMAND')116 print(sudo_run)117 prRed('''118 119Background Processes/Services Provide Invaluable Logs for A User's Activities:120 ''')121 122 123def scan12():124 cd6 = os.system('cd' + ' ' + '/root/')125 126def scan13():127 logc = os.system('cat' + ' ' + '/var/log/daemon.log')128 print(logc)129 prRed('''130 131Contains General System Messages. Particularly, It Also Contains Cron Job Execution With Its Associated Commands:132 ''')133def scan14():134 cd7 = os.system('cd' + ' ' + '/root/')135 136def scan15():137 logd = os.system('cat' + ' ' + '/var/log/syslog')138 print(logd)139 prRed('''140 141WebShell Access Detection Logs:142 ''')143def scan18():144 cd9 = os.system('cd' + ' ' + '/root/')145 146def scan19():147 loga = os.system('cat' + ' ' + '/var/log/apache2/access.log')148 print(loga)149 150 151 prRed('''152 153Monitor The Network For Unusual Network Traffic and Connections:154 ''')155 156def scan20():157 cd10 = os.system('cd' + ' ' + '/root/')158 159def scan21():160 logz = os.system('ps -auxwf')161 print(logz)162 163 164 prRed('''165 166MySQL Database Server Log File:167 ''')168 169def scan22():170 cd11 = os.system('cd' + ' ' + '/root/')171 172def scan23():173 logf = os.system('cat' + ' ' + '/var/log/mysqld.log')174 print(logf)175 176 177 prRed('''178 179Nginx Access And Error Logs Directory:180 ''')181 182 183def scan24():184 cd12 = os.system('cd' + ' ' + '/root/')185 186def scan25():187 logfs = os.system('cat' + ' ' + '/var/log/nginx/access.log')188 print(logfs)189 190 191 prRed('''192 193Kernel Log:194 ''')195 196 197def scan26():198 cd13 = os.system('cd' + ' ' + '/root/')199 200def scan27():201 logrt = os.system('cat' + ' ' + '/var/log/debug')202 print(logrt)203 204 205 prRed('''206 207As An event Responder, You Must Determine If There Are Any Anomalies In The Services:208 ''')209 210 211def scan28():212 cd14 = os.system('cd' + ' ' + '/root/')213 214def scan29():215 logrtc = os.system('service --status-all')216 print(logrtc)217 218 219 prRed('''220 221Open Network Ports Or Raw Sockets:222 ''')223 224 225def scan30():226 cd15 = os.system('cd' + ' ' + '/root/')227 228def scan31():229 logrtct = os.system('netstat -nalpn')230 print(logrtct)231 232 233 prRed('''234 235Process Working Directory:236 ''')237 238 239def scan32():240 cd16 = os.system('cd' + ' ' + '/root/')241 242def scan33():243 logrtcti = os.system('ls -alR /proc/*/cwd')244 print(logrtcti)245 246 247 prRed('''248 249Check Scheduled Tasks:250 ''')251 252 253def scan34():254 cd17 = os.system('cd' + ' ' + '/root/')255 256def scan35():257 logrtctis = os.system('systemctl list-timers --all')258 print(logrtctis)259 260 261 prRed('''262 263 ________ __ ________ __ 264/ |/ | / | / | 265$$$$$$$$/ $$ |____ ______ $$$$$$$$/ _______ ____$$ | 266 $$ | $$ \ / \ $$ |__ / \ / $$ | 267 $$ | $$$$$$$ |/$$$$$$ | $$ | $$$$$$$ |/$$$$$$$ | 268 $$ | $$ | $$ |$$ $$ | $$$$$/ $$ | $$ |$$ | $$ | 269 $$ | $$ | $$ |$$$$$$$$/ $$ |_____ $$ | $$ |$$ \__$$ | __ __ __ 270 $$ | $$ | $$ |$$ | $$ |$$ | $$ |$$ $$ |/ |/ |/ |271 $$/ $$/ $$/ $$$$$$$/ $$$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ 272 273 274 275 _ 276 //\lperen |U|gurlu 1992277 `-' 278 279 280 ''')281 282 283scan1()284scan3()285scan2()286scan4()287scan5()288scan6()289scan7()290scan8()291scan9()292scan10()293scan11()294scan12()295scan13()296scan14()297scan15()298scan18()299scan19()300scan20()301scan21()302scan22()303scan23()304scan24()305scan25()306scan28()307scan29()308scan30()309scan31()310scan32()311scan33()312scan34()...

Full Screen

Full Screen

watchdog.py

Source:watchdog.py Github

copy

Full Screen

...91 must be done manually, if no callback was provided92 """93 check = (datetime.datetime.now(), bool(value))94 self.checks[name]['results'].append(check)95 def log_reboot(self, failed):96 """log reboot reason"""97 message = 'Reboot system because of failed checks:\n'98 message += '\n'.join([item[1] for item in failed])99 logger.error(message)100 measurements = {101 'watchdog_message': {102 'message': message103 }104 }105 sqlite.store_dicts(measurements)106 def run(self):107 logger.debug("manager:run()")108 self.update_checks()109 failed = self.find_failed()110 if len(failed) > 0:111 # check other conditions112 uptime = get_uptime()113 logger.info("uptime is {}, {} needed before reboot".format(114 uptime, self.min_uptime_for_reboot))115 if uptime > self.min_uptime_for_reboot:116 # now we can reboot117 self.log_reboot(failed)118 reboot()119 def find_failed(self):120 """find failed checks121 Returns:122 failed_checks (list of tuples): list of tuples (name, message)123 """124 failed_checks = []125 for name in self.checks:126 results = self.checks[name]['results']127 logger.debug("results of check {} are {}".format(name, results))128 # we only keep no of min_fails_in_row results129 # therefore we need only count how many of them are failed130 failed_count = sum([1 for item in results if item[1] is False])131 if failed_count >= self.checks[name]['min_fails_in_row']:...

Full Screen

Full Screen

log_reboot.py

Source:log_reboot.py Github

copy

Full Screen

1#!/usr/bin/env python2import socket3import sys, os4import shutil5from datetime import datetime6import subprocess7import re8log_file_name = 'noappend.log'9now = str(datetime.now())10if sys.platform == 'win32':11 log_loc = 'Q:/log_reboot/'12 # make sure you set up a shared network drive.13 #log_loc = ''14else:15 log_loc = '/share/log_reboot/'16group = 'a'17pattern = "WATCHDOG: GPU (.*) hangs in OpenCL call, exit"18# you may place a different error message pattern depending on different miners. The above one is for all claymore miners.19def get_myip():20 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)21 s.connect(('8.8.8.8', 0))22 return s.getsockname()[0]23def get_failed_gpus(log_file_name, pattern):24 log = open(log_file_name,'r').read()25 result = re.findall(pattern, log)26 return list(set(result))27def save_log_file(worker_name, failed_gpus):28 with open(log_loc + worker_name + '.txt', 'a') as log_event:29 log_event.write("\n\r" + now + " Failed GPUs: " + str(failed_gpus))30 31 if not os.path.exists(log_loc + worker_name):32 os.makedirs(log_loc + worker_name)33 34 if os.path.exists(log_file_name):35 if sys.platform == 'win32':36 data = subprocess.check_output("powershell gc -TotalCount 50 %s" % log_file_name, shell=True)37 data += subprocess.check_output("powershell gc -Tail 50 %s" % log_file_name, shell=True)38 else:39 data = subprocess.check_output("head -50 %s" % log_file_name, shell=True)40 data += subprocess.check_output("tail -50 %s" % log_file_name, shell=True)41 with open(log_loc + worker_name + '/'+ now.replace(' ', '-').replace(':','-')[:16] + '.log', 'w') as log:42 log.write(data)43 44 print "Finished logging..."45 46def main():47 worker_name = group + '-' + get_myip()48 failed_gpus = get_failed_gpus(log_file_name)49 save_log_file(worker_name, failed_gpus)50if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful