0% found this document useful (0 votes)
7 views6 pages

Shell Scripting Paper

John, a junior systems administrator at TechCorp, faced disk space issues on the file server due to old log files and backups. He created a shell script to automate cleanup but initially archived important files, leading to complaints from the development team. After modifying the script to exclude critical files and adding logging for better monitoring, John learned the importance of testing automation scripts to avoid unintended consequences.

Uploaded by

ALLIAN MEHBOOB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Shell Scripting Paper

John, a junior systems administrator at TechCorp, faced disk space issues on the file server due to old log files and backups. He created a shell script to automate cleanup but initially archived important files, leading to complaints from the development team. After modifying the script to exclude critical files and adding logging for better monitoring, John learned the importance of testing automation scripts to avoid unintended consequences.

Uploaded by

ALLIAN MEHBOOB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CASE STUDY FOR LONG:

Scenario:

John is a junior systems administrator at TechCorp, a mid-sized 17 company. One of


his responsibilities is managing and maintaining the company's Flie servers.
Recently, John noticed that the server's disk space was rapidly filling up. After
investigating, he found that old log files and unused backups were taking up
significant space. John decided to write a shell script to automate the cleanup
process. The script identified files older than 30 days, compressed them, and moved
them to an archive directory, He also scheduled the script to run daily using cron
jobs. However, after a week, John received complaints from the development team
that some important files had been accidentally archived. To fix this issue, John
modified his script to exclude files in specific directories labeled as "critical and
added a logging mechanism to track the script's actions. This allowed him to monitor
which files were being archived and ensure that essential files were not affected.

QUESTION / ANSWERS:

Here are the answers to the questions based on the case study:

Q1: What sort of problem is John facing in the file server?

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.

The steps to solve the problem are:

1. Investigate the cause of the disk space issue.

2. Identify files that can be safely removed or archived.

3. Write a shell script to automate the cleanup process.

4. Schedule the script to run daily using cron jobs.

5. Modify the script to exclude critical files and add logging.

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?

John added a logging mechanism to track the script's actions.

Q7: Why did John choose to compress files instead of deleting?

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.

Q8: What is the purpose of scheduling a task using cron jobs?

The purpose of scheduling a task using cron jobs is to automate the task to run at a
specified interval, in this case, daily.

Q9: How does adding a logging mechanism improve the script?

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 ===

 = is an assignment operator (e.g., x = 5).

 == checks for value equality, ignoring type (e.g., "5" == 5 is True in


JavaScript).

 === 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

 The process of managing and responding to runtime errors to prevent


program crashes.

 Common methods:
o Try-Except (Python):

python

Copyedit

try:
x=1/0

except ZeroDivisionError:

print("Cannot divide by zero")


o Try-Catch (JavaScript, Java, etc.)
4. Environmental Variables
 Definition: System-level variables storing configuration settings.

 Types:

o System Variables (e.g., PATH, HOME)

o User Variables (specific to a user)

 Characteristics: Dynamic, temporary, inherited by child processes.

 Example (Python):

python

CopyEdit
import os

print(os.environ['PATH'])
5. Basic Commands (ls, cd)

 ls – Lists files and directories in the current directory.

o Example: ls -l (detailed list)

 cd – Changes the current directory.

o Example: cd /home/user (navigates to /home/user)


1. pwd

 Purpose: Prints the current working directory (the directory you are
currently in).
 Example:

 pwd

Output:
/home/user (or your current directory path).
2. sudo

 Purpose: Executes a command with superuser (root) privileges. You need


this for administrative tasks.
 Example:

 sudo apt update

This will run the apt update command as a superuser.


3. ls -la
 Purpose: Lists all files (including hidden ones) in a directory in long format
(detailed view with permissions, owner, size, etc.).
 Example:

 ls -la

Output:
-rwxr-xr-x 1 user user 12345 Jan 1 12:34 file.txt
4. trap

 Purpose: Used to specify commands to run when the script receives a


signal or exits, like handling errors.

 Example:

 trap 'echo "Error occurred"; exit 1' ERR

This will print an error message and exit the script if any command fails.
5. top

 Purpose: Displays real-time system information, including CPU usage,


memory usage, and running processes.
 Example:

 top

It shows a dynamic list of processes and system resources.


6. systemctl

 Purpose: Controls systemd services. You can start, stop, restart, or check
the status of services and manage the system.
 Example:

 sudo systemctl start apache2

This will start the Apache web server service.

OBJECTIVE PART
MCQs (10 marks, one-liner each)

1. Environmental Variable – System-level variables storing configuration


settings for processes.
2. Why Wildcards are Used in Shell Scripting – Wildcards (*, ?, [ ]) match file
patterns to simplify operations.
3. Output – The result displayed after executing a command or program.

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).

9. da/dd/df/DL Commands and Purposes – da (delete all), dd (delete line), df


(disk usage), DL (download).
10. File Permissions – Define who can read, write, or execute a file (chmod 755
file).

True/False (5 marks, one-liner each)

1. Conditional Execution Operations – Commands execute based on


conditions (&&, ||).
2. Function Return Value – A function can return a value using return or output
(echo in shell).
3. Definition of By Default Keywords – Reserved words with predefined
functionality (default in switch-case).
4. Wildcard Keywords Definition – Special symbols that match patterns (*, ?, [
]).
5. File Permissions – Defines access levels (rwx for user, group, others).

You might also like