Question writing a shell script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Question writing a shell script
# 1  
Old 04-05-2011
Question writing a shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
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. Relevant commands, code, scripts, algorithms:
ps, top, cmp, netstat


3. The attempts at a solution (include all code and scripts):

no clue

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Florida International University, Miami, USA, Professor Meyer, COP3348.

OK, so I am taking an intro Linux course and I am very new to linux. I have been having a tough time when it comes to shell scripting. I know the basic commands and how to create the file and also how to open vi to edit the file. But when it comes to starting the code I just dont know where or how to start. Ive contacted my professor and he suggested I get help through forums so here goes. Im not asking for anyone to do the HW for me I just was hoping someone could help me get a good start and explain it to me. Please, anything helps right now...
# 2  
Old 04-06-2011
Quote:
Originally Posted by qbnlnk
Im not asking for anyone to do the HW for me I just was hoping someone could help me get a good start and explain it to me. Please, anything helps right now...
OK, just a question: have you ever written any program in any programming language? If so (if not: learn that first, but that would be beyond the scope of such a thread), you sure could explain the (abstract) program flow necessary. Start writing this here and we will work from there.

I hope this helps.

bakunin
# 3  
Old 04-09-2011
I would start by providing a switch like this:
Code:
echo "Please select a program to run"
OPTIONS="ps top cmp netstat"
    select opt in $OPTIONS; do
        if [ "$opt" == "ps" ]; then
                    #logic for ps here
        elif [ "$opt" == "top" ]; then
                    #logic for top here
        elif [ "$opt" == "cmp" ]; then
                    #logic for cmp here
        elif [ "$opt" == "netstat" ]; then
                    #logic for netstat here
        else
                    echo "bad option"
        done
        fi
exit 0

the logic could just be another menu inside of this menu, but in that case, you might want to clear the screen, which is as simple as typing clear. However, if you're working with this, keep in mind that you need to enter the number of the option on the menu, and not the word on the menu. I hope this helps. Smilie
# 4  
Old 04-11-2011
Quote:
Originally Posted by Puddles187
I would start by providing a switch like this:
Code:
echo "Please select a program to run"
OPTIONS="ps top cmp netstat"
    select opt in $OPTIONS; do
        if [ "$opt" == "ps" ]; then
                    #logic for ps here
        elif [ "$opt" == "top" ]; then
                    #logic for top here
        elif [ "$opt" == "cmp" ]; then
                    #logic for cmp here
        elif [ "$opt" == "netstat" ]; then
                    #logic for netstat here
        else
                    echo "bad option"
        done
      fi
exit 0

Code:
echo "Please select a program to run"
OPTIONS="ps top cmp netstat"
    select opt in $OPTIONS; do
        if [ "$opt" == "ps" ]; then
                    #logic for ps here
        elif [ "$opt" == "top" ]; then
                    #logic for top here
        elif [ "$opt" == "cmp" ]; then
                    #logic for cmp here
        elif [ "$opt" == "netstat" ]; then
                    #logic for netstat here
        else
                    echo "bad option"
       fi
     done
 exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about writing a bash script

Hello, I want to write a bash script to delete the content after '#'. However, if '#' appears in a string with "", ignore this. For example, input file: test #delete "test #not delete" Output file: test "test #not delete" Does anyone know how to write this script? Thanks (1 Reply)
Discussion started by: jeffwang66
1 Replies

2. UNIX for Dummies Questions & Answers

Need help in writing shell script

Dear Team, Below is the list of steps i need to perform manually as of now and completely new to shell scripting, could you help in writing a shell script to perform the below procedure? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is already created (grep –i... (2 Replies)
Discussion started by: VKIRUPHAKARAN
2 Replies

3. UNIX for Dummies Questions & Answers

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (4 Replies)
Discussion started by: ShiGua
4 Replies

4. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

5. Shell Programming and Scripting

Writing a shell script

Hi I have two files a.log and b.log . i need to append a.log and b.log so that at the end of first line in a.log i need the append the data of first line from b.log and end of the second line in a.log i need to append the data of second line from b.log and so on up to the end of the file can... (3 Replies)
Discussion started by: lalu
3 Replies

6. UNIX and Linux Applications

Need help in writing shell script

I have written a shell script and when i ran the script,for some point of time it is asking to press enter key manually using keyboard.So i need it the enter key in shell itself. ex : in my shell script,i used the command ssh-keygen -t rsa so it asks the enter 3 times. can you please let me know... (3 Replies)
Discussion started by: lkeswar
3 Replies

7. Shell Programming and Scripting

Writing shell script

Hi, I am a new for shell script. i need to write script using the following commands cd /usres/test # create directory mkdir temp+DATE( i need to append date ) #moving files from one directory to this directory(we need to check total files in source and taget) cd /users/sample ... (2 Replies)
Discussion started by: bmkreddy
2 Replies

8. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

9. Shell Programming and Scripting

Need help for writing shell script

Hello ALL, I am fresher in Unix . i need help to write small shell script . Please help me unix guru. I am developing the internal site in my office . the data files are generated in one directory everyday . I have to write shell script to sort those files and put it is internal site . ... (3 Replies)
Discussion started by: deepa20
3 Replies

10. UNIX for Dummies Questions & Answers

Writing a shell Script

How to write a shell script file to read 5 numbers using a while loop. Finding the average, maximum and minumum for the numbers. Any help would be great. (1 Reply)
Discussion started by: Chin
1 Replies
Login or Register to Ask a Question