Linux Question

Description

Here is the assignment details:

Don't use plagiarized sources. Get Your Custom Assignment on
Linux Question
From as Little as $13/Page

Part 1: Scripting

Purpose

Scripts are an essential tool for system administrators. Scripts help an administrator automate menial tasks in the workplace, thus freeing them up for other tasks that require their attention.

Instructions:

Write a script that will assist you as a Linux administrator. A script is a text file with Linux commands you can execute. Your script must include a discipline you have learned during this class (mail, user accounts, etc.). You can reuse some code, as that is common practice; however, you must include code to make it original to you.

For the script, you need to show the script running on a Linux server. You need to show the scripts output. In the case of your script, you need to show it creating user accounts and then show that the account was created. Additionally, please add the screenshots of your script on the server after every step of the command.

For example:

# Function to display menu

display_menu() {

echo————————————”

echo ” Linux Administration Script Menu”

echo “—————————————”

echo “1. Create User”

echo “2. Delete User”

echo “3. List Users”

echo “4. Send Notification Email”

echo “5. Exit”

echo “—————————————”

}

After the above is ran, attach a screenshot.


Unformatted Attachment Preview

Part 1: Scripting
Below is a simple Bash script that incorporates some Linux administration tasks, focusing on
user account management and sending email notifications using the `mail` command. This script
assumes you have the `mail` command available on your system.
“`bash
#!/bin/bash
# Linux Administration Script
# Function to display menu
display_menu() {
echo————————————”
echo ” Linux Administration Script Menu”
echo “—————————————”
echo “1. Create User”
echo “2. Delete User”
echo “3. List Users”
echo “4. Send Notification Email”
echo “5. Exit”
echo “—————————————”
}
# Function to create a new user
create_user() {
read -p “Enter the username: ” username
sudo useradd -m $username
echo “User $username created successfully.”
}
# Function to delete a user
delete_user() {
read -p “Enter the username to delete: ” username
sudo userdel -r $username
echo “User $username deleted successfully.”
}
# Function to list all users
list_users() {
echo “List of Users:”
cut -d: -f1 /etc/passwd
}
# Function to send notification email
send_notification_email() {
read -p “Enter the recipient’s email address: ” email
read -p “Enter the subject: ” subject
read -p “Enter the message: ” message
echo “$message” | mail -s “$subject” $email
echo “Email sent successfully.”
}
# Main script
while true; do
display_menu
read -p “Enter your choice (1-5): ” choice
case $choice in
1) create_user ;;
2) delete_user ;;
3) list_users ;;
4) send_notification_email ;;
5) echo “Exiting script. Goodbye!”; exit ;;
*) echo “Invalid choice. Please enter a number between 1 and 5.” ;;
esac
read -p “Press Enter to continue…”
clear
done
“`
This script provides a simple menu for creating users, deleting users, listing all users, and
sending a notification email. Customize it further based on your specific needs and security
considerations for your environment. Always exercise caution when working with user accounts
and sending emails to ensure the security and integrity of your system.

Purchase answer to see full
attachment