exam questions

Exam XK0-004 All Questions

View all questions & answers for the XK0-004 exam

Exam XK0-004 topic 1 question 116 discussion

Actual exam question from CompTIA's XK0-004
Question #: 116
Topic #: 1
[All XK0-004 Questions]

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 Suggested Answer Hide Answer
Suggested Answer:

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Dracolitch
Highly Voted 3 years, 2 months ago
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
upvoted 5 times
Mr_Marcus
2 years, 2 months ago
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
upvoted 1 times
...
...
snood3935
Most Recent 2 years, 6 months ago
So what is the answer?
upvoted 2 times
...
Ya5
2 years, 10 months ago
I tested it and it worked with me by using "$log.[1-6]$" It didn't return any results with "log.[1-6]$"
upvoted 1 times
...
igm
4 years, 4 months ago
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
upvoted 1 times
ssc1982
4 years, 4 months ago
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
upvoted 3 times
...
...
igm
4 years, 4 months ago
could someone help with this one? grep $1 doesn't look right, I think it should be grep "log.[1-6]$
upvoted 3 times
ssc1982
4 years, 4 months ago
grep "$1" will search all the file named with the positional parameter and put the file name in to tempfile
upvoted 1 times
igm
4 years, 4 months ago
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
upvoted 1 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago