Question

In some cases, people who are not strong in Linux may need to run specific Linux...

In some cases, people who are not strong in Linux may need to run specific Linux commands. To make this easier, you can create a menu-driven program that runs these Linux commands. Such a program allows users to execute the commands without having to actually know about how to execute them. For this scenario, create a menu-driven program that has the following options:

1. List users who are logged in (using the who command)
2. List system information (using the uname -v command)
3. List the five largest files in the current directory (using the ls -lS command)
4. List basic CPU information (using the lscpu | head command)
5. Display system time (using the date command)
6. Exit the program

The program should continue in a loop until the user chooses option 6. The program should also produce an error message if an invalid option is chosen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
!/bin/bash

options=("1- List users who are logged in (using the who command)" "2- List system information (using the uname -v command)" "3- List the five largest files in the current directory (using the ls -lS command)" "4- List basic CPU information (using the lscpu | head command)" "5- Display system time (using the date command)" "6- Exit the program")
select num in "${options[@]}"
do
        case $num in
                "1- List users who are logged in (using the who command)")
                        who
                        ;;
                "2- List system information (using the uname -v command)")
                        uname -v
                        ;;
                "3- List the five largest files in the current directory (using the ls -lS command)")
                        ls -lS
                        ;;
                "4- List basic CPU information (using the lscpu | head command)")
                        lscpu | head
                        ;;
                "5- Display system time (using the date command)")
                        date
                        ;;
                "6- Exit the program")
                        break
                        ;;
                *) echo "Invalid Option";;

        esac
done

Here is the script to the linux bash shell program

ttt.sh File Edit Search Options Help !/bin/bash options=(1. List users who are logged in (using the who command) 2- List sy

Here is the executed program with screenshots:

root@kali: -/Desktop File Edit View Search Terminal Help root@kali:-/Desktop# chmod +777 ttt.sh root@kali:--/Desktop# chmod +

? 8 W. car File Edit View Search Terminal Help root@kali:-/Desktop# chmod +777 ttt.sh root@kali:-/Desktop# chmod +x ttt.sh ro

  • chmod +777 ttt.sh gives special permissions to the bash script which are read , write and execute.
  • chmod +x ttt.shmakes the bash script executable.
  • who command shows the users which are logged in.
  • uname -v is used to display the system information
  • ls -lS where ls lists the files in directory and -S sorts files by their size
  • lscpu | head gives cpu information. Pipe command gives the output of one command to the other command. Here lscpu output is given to head where "head" prints the toop n number of data.
  • date is used to print the present date.
  • exit command or break command can be used to exit a program.

This menu driven program has 7 different scenarios in which all of them are assignet with respective values. Once the user gives that value, the respective command gets executed and the user is shown the output of that command.

The input number should range from 1-7. If the input is given other than these commands, the user is shown as Invalid Option.


PLESAE UPVOTE IF THIS HELPED YOU.
THANKS

Add a comment
Know the answer?
Add Answer to:
In some cases, people who are not strong in Linux may need to run specific Linux...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check...

    LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check the output) Display the command(s) used to do the following: create an empty file called history by using just a redirection operator. Verify and show. Show/verify all results (i.e., all commands and their corresponding outputs). Wait 1 minute or more and then display the command(s) used to do the following: change the timestamp on the history file you just created. Verify/display the change. Show/verify...

  • Using Unix processes Submit a README file that lists the files you have submitted along with...

    Using Unix processes Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README. MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode. ForkCopy.c : Write a...

  • INFO 1211

    Lab 0: Essential UNIX OperationsObjectivesAt the end of this of lab, you should be able to:securely      log in to a remote computer running a UNIX-like operating systemread the      manual page for any commanduse the      UNIX file systemedit a      text fileNotes:·         In order to get familiar with UNIX, do all your work on UNIX.·         A command line interface may be harder to learn, but can be more powerful for scripting and automating tasks.·        ...

  • 1. Write the command to set the following permissions on a script file with the following...

    1. Write the command to set the following permissions on a script file with the following name; myscript.sh Owner: full access; read, write and execute Group: read and execute Other: no access 2. Create a new file with the name "myfirstscript.sh". Write a new script that performs the following tasks in sequence; Display the usernames of currently logged in users; sorted from a-z HINT: You will need to filter the output of the whocommand Display a list of usernames who...

  • I'm stuck, if you can provide the code I can put it into the BASH environment...

    I'm stuck, if you can provide the code I can put it into the BASH environment Executing tasks: In this section of the project, you will demonstrate your ability to execute Linux commands to create files and create and organize the Linux directory structure. At the end of this section, you will create a log file that will include a list of all the commands you used to complete these steps. VII. In the workspace directory, create new directories titled...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • Login to Suse Linux as root. Complete the task working as the root user. 1. What...

    Login to Suse Linux as root. Complete the task working as the root user. 1. What is your current directory. What did you enter at the command prompt to determine your current working directory? 2. Change directories if needed to find your foods (or food) file. Use vi to make the file contain 10 food items. Save your file and quit. Use the cat command, and option, and the argument food to display the food file with numbered lines. Use...

  • Unix/Linux The purpose of this lab is to practice the commands to manage and organize files...

    Unix/Linux The purpose of this lab is to practice the commands to manage and organize files and directories: How would one go about this? Thanks. Task 1: Preliminaries: 1) If you have not already done so, create a directory called bin under your HOME directory. 2) If you have not already made a copy (using ftp) of the file called famous.dat from the Assignment#1, do that now. 3) Make bin the active/working directory. Task 2: Perform all of the following...

  • do numbers 4-8 4. Given any directory, use the Is command to display: • all files...

    do numbers 4-8 4. Given any directory, use the Is command to display: • all files and sub-directories starting with the letter "D" (note do not list anything in any sub-directory) • its immediate sub-directories (sub-directories only, and no other ordinary files) its immediate hidden sub-directories only - take a screenshot (#3-3) that clearly shows the command and the result. 5. Assume that the following files are in the working directory: $ ls intro notesb ref2 section 1 section3 section4b...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT