Shell Scripting Paper
Shell Scripting Paper
Scenario:
QUESTION / ANSWERS:
Here are the answers to the questions based on the case study:
John is facing a problem of rapidly filling disk space due to old log files and unused
backups.
Q2: Steps to solve the problems faced by John in the file server.
Q3: Did John use any type of automation script for the cleanup of his process?
Yes, John wrote a shell script to automate the cleanup process.
Q4: When John implemented his automation script, what complaints and
problems were received by him?
John received complaints from the development team that some important files had
been accidentally archived.
Q5: What problem script was modified by John (the one he modified for
upgradation)?
John modified the script to exclude files in specific directories labeled as "critical".
Q6: For betterment of script monitoring, what addictive features did John use?
The case study doesn't explicitly state why John chose to compress files, but it's
likely to preserve the files for potential future use while reducing their storage
footprint.
The purpose of scheduling a task using cron jobs is to automate the task to run at a
specified interval, in this case, daily.
Adding a logging mechanism improves the script by providing a record of the script's
actions, allowing John to monitor which files are being archived and ensure that
essential files are not affected.
Q10: What lesson can be learned from John's approach to solve the issue?
The lesson that can be learned from John's approach is the importance of testing
and refining automation scripts to avoid unintended consequences, as well as the
value of adding logging mechanisms to improve script monitoring and
troubleshooting.
SHORT QUESTION/ANSWERS:
Here are the short answers for each topic (3 marks each):
1. Difference between =, ==, and ===
=== checks for both value and type equality (e.g., "5" === 5 is False in
JavaScript).
2. Difference between Absolute and Relative Path
Absolute Path: Specifies the complete location from the root directory (e.g.,
/home/user/file.txt).
Relative Path: Specifies the location relative to the current directory (e.g.,
./file.txt or ../file.txt).
3. Error Handling
Common methods:
o Try-Except (Python):
python
Copyedit
try:
x=1/0
except ZeroDivisionError:
Types:
Example (Python):
python
CopyEdit
import os
print(os.environ['PATH'])
5. Basic Commands (ls, cd)
Purpose: Prints the current working directory (the directory you are
currently in).
Example:
pwd
Output:
/home/user (or your current directory path).
2. sudo
ls -la
Output:
-rwxr-xr-x 1 user user 12345 Jan 1 12:34 file.txt
4. trap
Example:
This will print an error message and exit the script if any command fails.
5. top
top
Purpose: Controls systemd services. You can start, stop, restart, or check
the status of services and manage the system.
Example:
OBJECTIVE PART
MCQs (10 marks, one-liner each)
4. Loop for Showing Iterative Value – Repeats a block of code for multiple
iterations (for, while).
5. By Default Command of Process – The default shell (/bin/bash) runs
processes unless specified otherwise.
6. Index Number of Array – Arrays start from index 0 in most programming
languages.
7. File Manipulation – Operations like creating, modifying, renaming, or deleting
files (touch, rm, mv).
8. Grep Functionality – Searches for a pattern in files (grep "text" file.txt).