Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Unix Debian System Create a script with the following functionality: a. (3 point

ID: 3831379 • Letter: U

Question

Unix Debian System

Create a script with the following functionality:

a.    (3 points) The script takes a list of users from standard in. Note: this implies the script will be executed as   follows: cat /root/users | ./script.bash and the file that contains a list of users is a list with a one user per line

b.    (3 points) Before removing each user, you need to ensure the user exists (hint: use this $(cat /etc/password | egrep “^$username”) and see if it is an empty string)

c.    (3 points) If the user exists, remove the user and force the deletion of all directories

Explanation / Answer

You need to be a root user or have "sudo" access on the system to remove any user.

I understand the requirement but please be careful while executing in super user mode. You can corrupt the system if the users you are trying to delete have any associated process running.

#!/bin/bash

passwdFile="/etc/passwd"

while read username
do
exists=$(cat "$passwdFile" | egrep "^$username")

#Remove the directory if the result is not empty
if [ -n "$exists" ];then
deluser --remove-home "$username"
fi

done <&0

#In the above script if "deluser" command doesn't work then try with "userdel" ..

#Commands are different for different linux systems but for debian it should be "deluser".

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote