Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the bash program below to do the following: 1) Determine the file size 2) Set a limit to check if the file exceeds 200

Modify the bash program below to do the following:

1) Determine the file size

2) Set a limit to check if the file exceeds 200 MB

3) Add a conditional to check if it exceeds 200 MB then zip it and create a new replacement log

4) The script should not accept any parameters. It should look in a logs folder (SOME-PATH/logs) and iterate the checking/zipping functionality over all logs in that folder.

#!/bin/bash

# 1. Looks for a log file

logfile=$1

if [ ! -f $logfile ]; then

echo "log file not found $logfile"

exit 1

fi

# 2. Checks the size of disk usage

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;

do

echo $output

usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )

partition=$(echo $output | awk '{ print $2 }' )

# 3. If above threshold 90% then creates a new file

if [ $usep -ge 90 ]; then

echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)"

timestamp=`date +%Y%m%d`

newlogfile=$logfile.$timestamp

cp $logfile $newlogfile

cat /dev/null > $logfile

# 4. zip the old log file

gzip -f -9 $newlogfile

fi

done

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_2

Step: 3

blur-text-image_3

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

Students also viewed these Databases questions

Question

2. How much time should be allocated to the focus group?

Answered: 1 week ago

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago