
Concept explainers
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.

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Send the output to a file called FileOut.txt Make sure there is one line in the output file for each of output that is printed. In addition, format the average to have two digits of precision after the decimal point.arrow_forwardIn GOLANG, write a program that takes the file name on the command line and sums all the numbers in the file. There should be only one number on a line. The output of the program is that sum and the input file should be numbers.txt. numbers.txt: 10 20 30.5 11 2.5arrow_forwardyou will need to create the following textbook specified files. Use vi to create these files: test-file1 test-file2 test-file3 test-g test-sor respected test-u west coast alpha1 alpha2 practice caffeine names.tmp numbers.tmp What command results in a listing of the number of words and the number of lines in the files practice?arrow_forward
- find The find command takes a pattern as a command-line argument and recur- sively searches through directories to find a filename matching that pattern. It should print a relative path starting with "./" for every file/directory that matches. For example, running ./find 1s.c from within the hw2 directory should print ./1s.c. If run from the parent directory, the output would be . /hw2/1s.c. There may be multiple matches. If we run ./find .c from within the hw2 directory, we should see: ./find.c ./1s.c ./tree.c The output does not need to be sorted. If nothing matches, it shouldn't print anything. Pattern matching should be case sensitive.arrow_forwardWrite a program that will count the number of characters, words, and lines in a file. Words are separated by a white space character. Your program should prompt the user to enter a filename.arrow_forwardWrite a program that allows the user to enter name and phone number. Have the program accept input until ZZZ is entered for name. Output each record that contains name and phone number to a file called directory.txt. Write a program that will read the above directory.txt file and print its content on screen.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





