Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Use the program cronttab to create cron jobs that: Append the output of the command uptime to a file in your home directory. This should run every 4 minutes. Appends the disk space used in /var to a different file in your home directory. Include the date and time in some way. This should run 8 times a day, evenly spaced throughout the day. You can choose the times. Make sure you are recording just the disk space used by /var, and not the disk space used by the entire partition that /var is on. Also, don't use human readable mode, since you will not be able to see any changes in the values if you do this. Runs a python program (which you have to write) that searches through the file created in step 1 and outputs any lines where the 5-minute load average first goes above 2.00 and then the next line where the 5-minute load average is back below 2.00. Save the results to a third file in your home directory. This program should run once a day between 3 and 5 am. (You should make sure that your system has a high 5-minute load average at least once so you can test your script. See the program stress for a nice tool that can stress test your system.) For example, if the the 5-minute load averages were 0.00 1.53 2.67 3.99 2.02 1.75 0.98 2.13 1.88 Then you would output the entire lines containing 2.67, 1.75, 2.13 and 1.88 At the end of your Word document, include the answers to the following questions:

I'm stuck on the third part, my python script takes the uptime.txt file and pulls the ones where the average goes over 2.00, however, can't figure out how to record the first line after the average drops below 2.00 like the directions say.

My Script:

#!/usr/bin/env python

import os

def main():
highAVG = []
infile = open ('uptime.txt','r')
for line in infile.readlines():
line = line.strip()
nline = line.split()[-3:]
index = nline.pop(0)
index2 = nline.pop(0)
index3 = nline.pop(0)
avg = float(index.replace(',', ''))
avg2 = float(index2.replace(',', ''))
avg3 = float(index3.replace(',', ''))
if avg > 2.0:
highAVG.append(line)
if avg < 2.0:
highAVG.append(line)
elif avg2 > 2.0:
highAVG.append(line)
if avg2 < 2.0:
highAVG.append(line)
elif avg3 > 2.0:
highAVG.append(line)
if avg3 < 2.0:
highAVG.append(line)
infile.close()

outfile = open ('High_load_avg', 'w')
for line in highAVG:
print(line)
outfile.write(line + '\n')
outfile.close()

if __name__=='__main__':
main()

 

The output:

02:12:01 up 7 days, 5:28, 1 user, load average: 7.67, 4.06, 1.74
02:16:01 up 7 days, 5:32, 1 user, load average: 2.70, 4.65, 2.61
02:20:01 up 7 days, 5:36, 1 user, load average: 0.07, 2.09, 2.01
02:24:02 up 7 days, 5:40, 1 user, load average: 3.12, 2.07, 1.96
03:12:01 up 7 days, 6:28, 1 user, load average: 4.66, 1.93, 0.83
03:16:01 up 7 days, 6:32, 1 user, load average: 7.96, 5.30, 2.48
03:20:01 up 7 days, 6:36, 1 user, load average: 0.47, 3.32, 2.40

Between the first two lines, I need the line where the load average drops below 2.00

I've posted this question three times, the first two times they recycled the python script from a previous question asked by someone else. That script obviously doesn't work. The third time wasn't any help at all.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education