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

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 DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

3. Job rotation is used for all levels and types of employees.

Answered: 1 week ago