Assessment 2 - Linux
Assessment 2 - Linux
ADP - Assignment 2
Q 1. You have a directory with multiple text files. Write a shell script that renames
all files in the directory by adding a timestamp to their names.
bash
#!/bin/bash
To use this script, save it in a file with a `.sh` extension (e.g., `rename_files.sh`),
make it executable (`chmod +x rename_files.sh`), and then run it
(`./rename_files.sh`). The script will add a timestamp to the names of all files in the
directory and display the renamed files.
Q 2. Create a shell script that takes a number as input and checks if it's even or
odd. If it's even, use a loop to print the numbers from 2 to the input number.
bash
#!/bin/bash
Q 3. Write a script that takes two filenames as command line arguments. The script
should compare the contents of the two files and display a message indicating
whether they are identical or not.
bash
#!/bin/bash
bash
#!/bin/bash
bash
#!/bin/bash
# Schedule the script to run every day at a specific time using cron
# Replace "0 0 * * *" with your desired schedule (e.g., "30 9 * * *" for 9:30 AM every
day)
echo "0 0 * * * $(pwd)/$(basename "$0")" | crontab -
To use this script, save it in a file with a `.sh` extension (e.g., `schedule_task.sh`),
make it executable (`chmod +x schedule_task.sh`), and then run it
(`./schedule_task.sh`). The script will run the time-consuming task in the background,
display a message indicating that the task has started, schedule the script to run
every day at a specific time using `cron`, and display a message indicating that the
scheduling is complete.
To change the permissions of a file so that only the owner can read and write to it,
while others cannot access it, you can use the `chmod` command in Linux. Here's
how you can do it:
1. Open a terminal and navigate to the directory where the file is located.
2. Use the `ls -l` command to list the files in the directory and view their current
permissions. Identify the file for which you want to change the permissions.
- 4: Read permission
- 2: Write permission
- 1: Execute permission
- 0: No permission
To give read and write permissions to the owner and remove all permissions for
others, you can use the following command:
bash
chmod 600 filename
Here, `6` represents read and write permissions for the owner, and `0` represents no
permissions for the group and others.
4. After executing the command, you can verify the changed permissions by using
the `ls -l` command again. The file should now have the desired permissions.
Q 2. Write a script that finds and displays the top 5 processes consuming the most
CPU and memory on your system.
bash
#!/bin/bash
To use this script, save it in a file with a `.sh` extension (e.g., `top_processes.sh`),
make it executable (`chmod +x top_processes.sh`), and then run it
(`./top_processes.sh`). The script will display the top 5 processes consuming the
most CPU and memory on your system.
Q 3. Create a script that compresses a directory and its contents into a tarball. Set it
up to be run as a scheduled task using `cron` every Sunday night.
bash
#!/bin/bash
# Directory to be compressed
directory="/path/to/directory"
To set up this script as a scheduled task using `cron` to run every Sunday night,
follow these steps:
1. Open the crontab file for editing by running the command `crontab -e`.
2. Add the following line to the crontab file to schedule the script to run
every Sunday at 11:59 PM:
59 23 * * 0 /path/to/script.sh
Now, the script will run automatically every Sunday night at the specified time,
compressing the specified directory into a tarball and saving it to the destination
directory.
Introduction to Git:
Q 1. Imagine you are starting a new software project. Describe the steps you would
take to create a new Git repository for your project and link it to a remote repository
on GitHub.
git init
git add .
6
This will add all the files in the current directory to the staging area.
- Commit the changes with a meaningful message using the following
command:
This will push the changes to the `master` branch of the remote repository.
Q 2. You are working on a feature for your project. Create a Git branch for this
feature, make several commits, and then merge the feature branch back into the main
branch (usually 'master').
git add .
git commit -m "Commit message 1"
5. Once you have made all the necessary commits on the feature branch, switch
back to the main branch:
If there are no conflicts, Git will automatically perform the merge. If there are
conflicts, you will need to resolve them manually.
This will update the main branch on the remote repository with the changes
from the feature branch.
7
Q 3. You are collaborating with a team on GitHub. Explain how you would clone the
repository, make changes, and push those changes to the remote repository.
2. Make changes:
- Navigate into the cloned repository directory using the `cd` command.
- Use a text editor or any other tool to make the desired changes to the files in
the repository.
git add .
- This will stage all the modified files for commit. If you only want to stage
specific files, replace `.` with the file names.
- Run the following command to commit the changes:
git push
- If it's your first time pushing to the repository, you may need to specify the
remote branch using:
Replace `<branch-name>` with the name of the branch you want to push to.
After successfully pushing your changes, they will be reflected in the remote
repository, and your team members will be able to see and review them.
8
Waterfall Model:
Advantages:
Disadvantages:
1. Limited flexibility: The Waterfall model does not easily accommodate changes
or iterations once a phase is completed. This can be problematic if requirements
change or if feedback from stakeholders is received later in the project.
2. Late feedback: Since testing and user feedback typically occur towards the
end of the project, any issues or necessary changes may be identified late in the
development cycle, leading to potential delays and increased costs.
Agile Model:
Advantages:
1. Flexibility and adaptability: The Agile model allows for iterative development,
enabling changes and adjustments to be made throughout the project based on
feedback and evolving requirements.
3. Early detection of issues: Frequent testing and iterations in Agile allow for
early detection and resolution of issues, reducing the risk of major problems later in
the development process.
Disadvantages:
2. Potential for scope creep: The flexibility of Agile can lead to scope creep if
requirements are not properly managed and controlled.
9
3. Uncertain timelines and costs: Agile projects may have less predictable
timelines and costs due to the iterative nature of development.
Based on the provided context of the project being a software development project,
the Agile model may be more suitable. The digital marketing landscape is constantly
evolving, and an Agile approach can provide the necessary flexibility to adapt to changing
requirements and market conditions. Additionally, the involvement of stakeholders
throughout the development process can help ensure that the final product meets their
needs effectively. However, it is important to consider the specific requirements and
constraints of the project before making a final recommendation.
Q 2. You are part of a Scrum team. Explain how the Scrum framework and its core
practices like sprint planning, daily stand-up, and retrospectives help in managing
and delivering a software project.
As part of a Scrum team, the Scrum framework and its core practices play a crucial
role in managing and delivering a software project effectively. Here's how each of
these practices contributes to the overall success of the project:
1. Sprint Planning:
Sprint planning is a collaborative meeting where the team determines what
work will be done during the upcoming sprint. It involves two main questions:
"What will we do this sprint?" and "How will we do it?". This practice helps in
setting clear goals and priorities for the team, ensuring that everyone is
aligned on what needs to be accomplished. By breaking down the work into
manageable tasks, the team can estimate effort and plan accordingly.
3. Retrospectives:
Retrospectives are held at the end of each sprint to reflect on the team's
performance and identify areas for improvement. During this meeting, the
team discusses what went well, what could have been done better, and any
potential changes to enhance future sprints. Retrospectives foster a culture of
continuous improvement, enabling the team to learn from their experiences
and make adjustments to their processes, communication, and collaboration.
This practice helps in refining the team's approach and increasing their
efficiency and effectiveness over time.
By following these core practices of the Scrum framework, a software project can
benefit in several ways:
Overall, the Scrum framework and its core practices provide a structured approach to
managing software projects, fostering collaboration, adaptability, and continuous
improvement. By following these practices, teams can effectively plan, execute, and
deliver high-quality software products.
Extreme Programming (XP) and Lean Software Development are both agile software
development methodologies that aim to improve the efficiency and effectiveness of software
development projects. However, they have different principles and practices. Let's compare
and contrast them:
Principles:
Key Practices:
Suitability:
Principles:
Key Practices:
2. Kanban: Visualizes the workflow, limits work in progress, and optimizes the
flow of work.
Suitability:
*******************