Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 5th, 2011, 09:43 PM
qbnlnk qbnlnk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 1 qbnlnk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 9 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old April 6th, 2011, 04:26 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,107 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 3 h 57 m 31 sec
Reputation Power: 1485
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:

Code:
functionA () {
}
functionB () {
}
ShowMenu() {
  say "A) - Run ps"
  say "B) - Run top"
  say ""
  say "Q) - Quit"
}
choose=""
while $choose <> "Q"
  ShowMenu
  valid=0
  while $valid = 0
    say "Enter choice: "
    read choose
    case $choose
       when "A"
          functionA
          valid=1
       when "B"
          functionB
          valid=1
       when "Q"
          say "Goodbye!"
          valid=1
          exit
       otherwise
          say "Invalid option!"
          valid=0
    end-case
  end-while
  say "Press enter to continue"
end-while
__________________
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Help with my assignment

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap