Menu

(Solved) : Exercise 1 Write Shell Script Loops Etc Passwd File One Line Time Prepend Line Line Number Q34222001 . . .

Exercise 1:

Write a shell script that loopsthrough the /etc/passwd file one line at a time. Prepend each linewith a line number followed by a colon and then a space.

Example output:

1: root:x:0:0:root:/root:/bin/bash

2: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin

3: bin:x:2:2:bin:/bin:/usr/sbin/nologin

4: sys:x:3:3:sys:/dev:/usr/sbin/nologin

Exercise 2:

Write a shell script that asks theuser for the number of lines they would like to display from the/etc/passwd file and display those lines.

Example output:

How many lines of /etc/passwd would you like to see? 3root:x:0:0:root:/root:/bin/bash

daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologin

Exercise 3:

Write a shell script that that allowsa user to select an action from the menu. The actions are to showthe disk usage, show the uptime on the system, and show the usersthat are logged into the system. Tell the user to enterq​​ to quit. Display “Goodbye!” just before thescript exits.

If the user enters anything other than1​​, ​2​, ​3​,or ​q​, tell them that it is an “Invalidoption.”

You can show the disk usage by usingthe df​​ command. To show the uptime, use theuptime​ command. To show the users logged into thesystem, use the who​ ​ command. Print a blank lineafter the output of each command.

Example output:

  1. Show disk usage.
  2. Show system uptime.
  3. Show the users logged into the system.

What would you like to do? (Enter q to quit.) 2

14:59:08 up 3 days, 7:36, 7 users, load average: 0.13, 0.22,0.33

  1. Show disk usage.
  2. Show system uptime.
  3. Show the users logged into the system.

What would you like to do? (Enter q to quit.) 4

Invalid option.

  1. Show disk usage.
  2. Show system uptime.
  3. Show the users logged into the system.

What would you like to do? (Enter q to quit.) q

Goodbye!

Expert Answer


Answer to Exercise 1 Write Shell Script Loops Etc Passwd File One Line Time Prepend Line Line Number Q34222001 . . .

OR