XK0-004 Exam QuestionsBrowse all questions from this exam

XK0-004 Exam - Question 114


DRAG DROP -

As a Systems Administrator, to reduce disk space, you were tasked to create a shell script that does the following:

Add relevant content to /tmp/script.sh, so that it finds and compresses rotated files in /var/log without recursion.

INSTRUCTIONS -

Fill the blanks to build a script that performs the actual compression of rotated log files.

If at any time you would like to bring back the initial state of the simulation, please click the Reset All button.

Select and Place:

Show Answer
Correct Answer:

Discussion

5 comments
Sign in to comment
Dracolitch
Feb 1, 2022

Correct script code (tested) #!bin/bash #name:script.sh find /var/log -maxdepth 1 -type f | grep "log.[1-6]$" > /tmp/tempfile for filename in $(cat /tmp/tempfile) do gzip $filename done

Mr_Marcus
Feb 19, 2023

Wrong. First, the question does not ask for files with "log" in the name (it doesn't even ask for log files - it says "related files"). Second, some of the files in /var/log do not have log or .log anywhere in the filename (e.g. messages, secure, spooler, etc.) and would be missed using your syntax. Third, I seriously doubt you tested it if your first line is incorrect... It's #!/bin/bash Your version will (likely) create an empty tempfile and compress nothing. And, yes, I've tested your solution (and mine). The correct answer is: #!/bin/bash #name: script.sh find /var/log -type f -maxdepth 1 | grep "$1" > /tmp/tempfile for filename in $(cat /tmp/tempfile) do gzip $filename done

igm
Dec 21, 2020

could someone help with this one? grep $1 doesn't look right, I think it should be grep "log.[1-6]$

ssc1982
Dec 23, 2020

grep "$1" will search all the file named with the positional parameter and put the file name in to tempfile

igm
Dec 23, 2020

Hi @ssc1982, thanks for your reply and help. the question is not mentioning that the script will have positional parameters and "log.[1-6]$" regular expression will allow grep to find those logs... rights? Thanks again

snood3935
Oct 22, 2022

So what is the answer?

igm
Dec 23, 2020

Hi @ssc1982, thanks for your reply and help. the question is not mentioning that the script will have positional parameters and "log.[1-6]$" regular expression will allow grep to find those logs... rights? Thanks again

ssc1982
Dec 27, 2020

It says in the question that " Add relevant content to /tmp/script.sh, so that it finds and compresses rotated files in /var/log without recursion" , there are a variety of different logs under the directory /var/log, not all the log start with log.*, using a positional parameter better match "Add relevent content to the /tmp/script.sh", I think

Ya5
Jun 20, 2022

I tested it and it worked with me by using "$log.[1-6]$" It didn't return any results with "log.[1-6]$"