Question: Purpose Demonstrate the ability to use text editors in the shell. Demonstrate the ability to create and execute shell scripts. Demonstrate the ability to create

Purpose

Demonstrate the ability to use text editors in the shell. Demonstrate the ability to create and execute shell scripts. Demonstrate the ability to create and compile multi-file C++ programs. Demonstrate the ability to access the command line arguments from within a C++ program. Demonstrate proficiency in logging your console input/output using the script command.

Assignment Log all the work you do in the bash shell using the script command (see the Session Logging section below). You will need to get logging working BEFORE you perform any of the steps listed below. You will need to turn in the session log files. See Deliverables below. With script logging enabled and working with a timing file, write a program that consists of two C++ source files and a header file (.h file). The first C++ file contains the main() routine and the second file contains a C++ function. The function prototype should be included in the header file. From within main(), you must display the count of command line arguments to stdout. Further, you must display the value of each command line argument to stdout. Finally, you must call the procedure that is defined in the second file. From within the procedure defined in the second file, you must display a log message that states you are inside the procedure. This log message must be sent to stderr.

You are then to create a shell script for compiling your code. The script will individually compile each file and generate the intermediate object file. Once the object files are created, the script will call the linker and link the object files into an executable. Your shell script should echo what it is doing at each step to stdout. You are then to create a second shell script that will run your program several times with varying command line arguments. Each time you call your program, you should append the stdout to an output file called stdout.log and you should append the stderr to an output file called stderr.log. Your shell script should echo what it is doing at each step to stdout.

Session Logging Session logging will be performed using the Linux script command. For details, see the man page for script (i.e. man script). For this assignment, you MUST include the creation of a script timing file when you run script. Make sure that you are careful to NOT OVERWRITE any older script files you may have previously created. script will overwrite a file if you give it a file name that already exists. See the a option to protect against this. You may exit the script program by typing: CTRL-D. You can either keep one long log file that spans multiple login sessions, or you can create multiple log files (or both). See Notes below for more info.

Notes If the compiler complains that /tmp is full (No space left on device), then set your TMPDIR environment variable to /scratch. You can do this in your bash shell and in your shell scripts like this TMPDIR=/scratch; export TMPDIR For the script command, I recommend you use the following to start each session. This will generate two files (but not overwrite them): typescript and script.timing You must turn in these files with your code: Be careful to NOT delete these two files. script append timing=script.timing All editing must be done within the shell using a text editor.

Example Output

$> compile.sh

Setting TEMPDIR environment variable to /scratch Compiling file1.cc Compiling file12.cc Linking files to create executable hw1 Done

$> run.sh

Running 'hw1' with 0 arguments: stdout appended to stdout.log stderr appended to stderr.log

Running 'hw1' with 1 argument: stdout appended to stdout.log stderr appended to stderr.log

Running 'hw1' with 5 arguments: stdout appended to stdout.log

stderr appended to stderr.log

$> more stdout.log

argc was: 1 ./hw1 Done! argc was: 2 ./hw1 abc Done! argc was: 6 ./hw1 a b c d e Done!

$> more stderr.log

Inside proc1() as stderr Inside proc1() as stderr Inside proc1() as stderr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!