Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

I've used the python program below

#!/usr/bin/env python

import os

def find_load_average():

with open('~/uptime.txt, 'r') as f:

for line in f :

if 'load average:' in line

return line.split()[-3:]

def main():

load average = find_load_average()

if float(load_average[0]) > 2.0:

with open ('~/high_load_average.txt', 'a') as f:

f.write(' '.join(load_average) + ' ')

if__name__=='__main__'

main()

However, this doesn't work. I get an error for unable to turn '0.00,' into a float. I edited the line to if float(str(load_avgerage[0].replace(',', ''))) > 2.0:

This fixed that issue, but when the program runs no file is created or saved. When trying to figure out why, printing the return value from find_load_average(): only one line is printed, which leads me to believe something is incorrect with the for loop.

This is a sample of what is in the uptime.txt file

01:40:01 up 7 days, 4:56, 2 users, load average: 0.00, 0.00, 0.00 01:44:01 up 7 days, 5:00, 1 user, load average: 0.00, 0.00, 0.00 01:48:01 up 7 days, 5:04, 1 user, load average: 0.00, 0.00, 0.00 01:52:01 up 7 days, 5:08, 1 user, load average: 0.00, 0.00, 0.00 01:56:01 up 7 days, 5:12, 1 user, load average: 0.00, 0.00, 0.00 02:00:01 up 7 days, 5:16, 1 user, load average: 0.05, 0.02, 0.00 02:04:01 up 7 days, 5:20, 1 user, load average: 0.22, 0.33, 0.14 02:08:01 up 7 days, 5:24, 1 user, load average: 0.39, 0.64, 0.33 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 02:28:01 up 7 days, 5:44, 1 user, load average: 0.06, 0.93, 1.51 02:32:01 up 7 days, 5:48, 1 user, load average: 0.00, 0.41, 1.15

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

Students also viewed these Databases questions

Question

2) fildde

Answered: 1 week ago