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

Write a Bourne / BASH script that does the following: Prompts the human watching

ID: 3765305 • Letter: W

Question

Write a Bourne / BASH script that does the following: Prompts the human watching the screen to enter their first name and give the human the ability to select from options: a, b or c (or select any multi-input combination thereof, such as: a b, b c, a b c, a c, c b, etc.) on the keyboard depending which information the human wants, and then the script provides the requested information. Details on the options a, b or c mentioned above: (a) Determines the number of potential users for the system by getting a count of the number of passwords contained in the system's password file (human or daemon users is OK). (b) Determines the number of (just human - OK) users currently logged in to the system. (c) Determines the number of processes being currently run by the users who are currently logged in. Note: Item (c) is very UNIX/Linux dialect dependent. This script is to be run without any input from the keyboard other than being invoked (started) and the human inputting desired options. The script outputs the student's first name, last name and student id, followed by the information requested. Hint 1: Implementing this assignment with "OR" logic conditionals is easier than implementing with "AND" logic conditionals. Hint 2: Implementing with compound OR logic will greatly reduce the number of lines of code needed. A compound OR has more than one OR in it. For example: A or B or C. Hint 3: For your algorithm design, consider using "On-The-Fly" approach (popular with Unix/Linux) rather than storing state information in an array followed by multiple passes through the array to determine the correct output. The assignment can be completed with just conditional logic. Loops are not required. Note: Students without On-The-Fly algorithm/thought experience may find this assignment may take a few do-overs to get it right. Students attempting to use state arrays may find they will need to independently research BASH looping structures before attempting the assignment.

Explanation / Answer

Solution:

#!/bin/bash

echo -e "Enter the student name "

read firstname

echo -e "a) Number of users "

echo -e "b) Number of online users "

echo -e "c) Number of process used by active users "

echo -e "Enter the choice> "

read choice

echo -e "You entered: $choice "

case "$choice" in

        "a")

        #read the passwd file copy to user.txt

        cat /etc/passwd>user.txt

        set `wc -l user.txt`

        #command to get the count of total number of users

      echo "There are $1 users in network "

        ;;

        "b")

        cat /etc/passwd>user.txt

        set `wc -l user.txt`

        #command to get the count of online users

   log=`who|wc -l`

        echo "There are $log user logged in right now"

        ;;

        "c")

        #command to print the users and their processors

        ps -eo user=|sort|uniq -c

        ;;

esac

Result:

enter the student name

sruthi

a) Number of users

b) Number of online users

c) Number of process used by active users

Enter the choice>

c

You entered: c

      2 avahi

      1 dbus

      3 haldaemon

    100 root

      1 rpc

      1 smmsp

      4 spiuser

      1 xfs  

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