Making a bash script and small C program for a homework assignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making a bash script and small C program for a homework assignment
# 1  
Old 04-25-2013
Making a bash script and small C program for a homework assignment

Here's the assignment. I'll bold the parts that are rough for me. Unfortunately, that's quite a bit lol. The syntax is, of course, where my issues lie, for the most part. I don't have a lot of programming experience at all :/. I'd post what I've already done, but I'm so lost I really don't know where to start.
  • Login to your account on our Unix server
  • Type bash <enter>
  • You should have a directory named cs371 inside your home directory (from Assignment 1). Change into the cs371 directory. You are now in a directory which I will refer to as /home/me/cs371, where me is your login name.
  • Inside this /home/me/cs371 directory, create a subdirectory named assn7. (There should be an assn1 subdirectory from Assignment 1. We won't need that right now, though.)
  • Inside the current /home/me/cs371/assn7 directory, place the script a7.sh and the C program a7.c that you will write, which are described below. Make sure to set the permissions to 700 on your script so that you can run your script.
  • After you have put your completed a7.sh script and a7.c C program in the /home/me/cs371/assn7 directory, type
    script myOutput7.out <enter>. Then, type pwd <enter>. Then, type date <enter>.
    Then, using the cc C compiler on uxb3 with option -o, compile your a7.c program to make an executable named a7.out. Then run your a7.out executable file. Then, type exit <enter>.
The a7.sh script:
Create a script named a7.sh using the vim editor that can be run in a bash shell.
  • The first line of your script should be the she-bang line. It should specify that a bash sub-shell be created for running the script.
  • Your script should be documented properly with comments, which begin with the pound symbol #. At the top of your script file (below the she-bang line), you should have a comment with your name, the assignment number and the date. Next to each command you should have a comment explaining what the command does.
  • Your a7.sh script should contain a function distinctNos that uses three parameters. All three parameters should be integers. The function is a "success" (with exit status 0) if there are exactly three parameters and they are distinct numbers. The function should have an exit status of 1 if there are three parameters but they are not all distinct numbers. The function should should have an exit status of 2 if there are fewer or more than 3 parameters.
  • Also, in a7.sh, you should call your function distinctNos with three parameters 55 -3 12
  • Also, in a7.sh, you should print an appropriate message to the standard output after calling distinctNos with parameters 55 -3 12 to say whether or not there were three parameters and whether or not they were distinct numbers. Use an if conditional and the exit status on your function call to do this. This if conditional may not be in the function distinctNos. (Your code should work if I were to change the parameters used on your function call.)


The a7.c C program:
Create a C program named a7.c using the vim editor that can be compiled using cc and executed on uxb3.wiu.edu.
  • Your program should be documented properly with comments. At the top of your file you should have a comment with your name and the assignment number. Next to each command you should have a comment explaining what the command does. You must also use proper indentation.
  • Your a7.c program should use printf to print a nice message. (You can decide what to say.) Then the process should use the fork system call to create a child process. Then, your code should do different things depending on whether the process is the parent or the child:
    • The parent should print one more message (using printf) saying that it is the parent, what its PID is, and what its child's PID is. It should then contain the command sleep(9);
    • The child process should use the execl system call to load and run your a7.sh script.
Anyways, if someone could help me out, I'd be very thankful Smilie
# 2  
Old 04-26-2013
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making bash script allways executable when transfer ?

Does it possible to make some bash script automatic to be a executable when transfered to another pc...? (5 Replies)
Discussion started by: tomislav91
5 Replies

2. Shell Programming and Scripting

Bash script for making complexes of ligands and receptor

I am working with autodock vina for virtual screening and docking with cygwin. Autodock vina generates conformers for multiple ligands. I want to make the complex of these conformers with receptor. e.g. I have 100 .pdbqt files form vina output and one receptor pdbqt file. By running command- cut... (1 Reply)
Discussion started by: Rajesh Patil
1 Replies

3. Shell Programming and Scripting

Assistiance in small bash script

Hi All, i wrote an simple script, that will monitor some services ,and if particular service will found down ,the code will restarts the service and message about the process will be sent on mail. I have a problem somewhere in the syntax that the script initializes the service even if is up... (6 Replies)
Discussion started by: Aviel.shani
6 Replies

4. Shell Programming and Scripting

Help in making a basic bash script

Hi All, I am trying to monitor CPU load of few processes, with the same name. The output that I get from top is the following 28171 root 20 0 1089m 21m 3608 S 103 0.3 15:16.89 /opt/ppp//h264rtptranscoder.bin --videoPort=14504 --audioPort=14505 27589 root 20 0 1060m 23m... (3 Replies)
Discussion started by: liviusbr
3 Replies

5. Shell Programming and Scripting

Small Assignment

1. Write a menu driven shell program to a. Display calendar of current month. b. Search for a pattern in all the files/subdirectories from current directory. c. Count the no. of directories / sub directories in current directory. 2. Display day of week for a given date. (ddmmyyyy).... (4 Replies)
Discussion started by: jainitai
4 Replies

6. Shell Programming and Scripting

CPU assignment bash script

Hi guys, I'm basically looking for some help with a bash script I've written. It's purpose is to assign process to individual CPU cores once that process hits 15% CPU usage or more. If it drops below 15%, it's unassigned again (using taskset). My problem is that I can't think of a way to... (2 Replies)
Discussion started by: mcky
2 Replies

7. Shell Programming and Scripting

A small project with bash script and craigslist

Before I start, I'm posting this for community knowledge, not to offend anyone. I thought it was an interesting project so that's why I'm sharing it. In the notorious erotic classified ads of craigslist, thousands of individuals post classifieds, using the internet to sell themselves with an... (0 Replies)
Discussion started by: hexpill
0 Replies

8. Shell Programming and Scripting

Making a progress gauge in a bash script

Hello once again: One thing that seems to be a nice feature is a progress gauge... so I can see how long an operation will take for a task to complete if it is requiring a lot of processing or the file is enormous. I have seen references to gauge operations, but I don't know anything about it or... (1 Reply)
Discussion started by: ccox85
1 Replies

9. UNIX for Dummies Questions & Answers

Learning to script...want a project to work on (making a small MUD)

Will it be possible to make a MUD using unix script(bash)? I know I can easilly make a "dungeon" with different rooms I can run through and such(kinda like a maze game) . What I did was made a differnt shell script for each room and used CASE for the different places to go, ex. when you press N for... (2 Replies)
Discussion started by: learningtoscrip
2 Replies
Login or Register to Ask a Question