1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Rep Power

    Help with my assignment

    I am a rookie linux user, I have to turn in the following assignment, can someone please guide me in the right direction. I know how to create the file and how to open vi to edit the file. But when it comes to coding it, I have all this material in the textbook in front of me but I just dont know where to start. Any help will be greatly appreciated.

    Write a shell script that allows the user to run the following commands:

    * ps
    * top
    * cmp
    * netstat

    Once the user has selected the command, the program should ask the user what options they wish to use with the command (file paths, etc) and pass the command to the appropriate utility program displaying the information to the screen. At the end of the execution of the command, and whatever output is given, the system should pause (the user should be able to see the results) - and then ask the user if they want to continue. If so redisplay the menu, if not end the script.
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    This will cover quite a few of the basic concepts in scripts. As it's a learning exercise it would be unfair just to hand you a ready-to-run script. A lot of the learning is done by making errors and finding out why they are errors and fixing them. So ... let's start with some basic hints!
    I would use functions to handle the details of running of the actual commands (getting options, etc.). It will just make things a little tidier and self-contained.
    You will want to output the menu in a loop - exiting once the user selects the 'exit/quit' option. The user selection should also be in a loop, until they pick a valid selection.

    Thus, in pseudo-code, something like:

    functionA () {
    functionB () {
    ShowMenu() {
      say "A) - Run ps"
      say "B) - Run top"
      say ""
      say "Q) - Quit"
    while $choose <> "Q"
      while $valid = 0
        say "Enter choice: "
        read choose
        case $choose
           when "A"
           when "B"
           when "Q"
              say "Goodbye!"
              say "Invalid option!"
      say "Press enter to continue"
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo