0

input and returning the input: output. Here is the assignment

In the session, provide a command prompt that includes the working directory, e.g., $./logger /home/it244/it244/hw8$

Accept user’s commands, execute them, and display the output on the screen.

During the session, create a temporary file “PID.cmd” (PID is the process ID) to store the command history in the following format (index: command):

1: ls

2: ls -l

If the script is aborted by CTRL+C (signal 2), output a message “aborted by ctrl+c”.

When you quit the logging session (either by “exit” or CTRL+C),

a. Delete the temporary file

b. Print out the total number of the commands in the session and the numbers of successful/failed commands (according to the exit status).

here is my code so far (which did not go well, I would not try to run it)

#!/bin/sh
  trap 'exit 1' 2
  trap 'ctrl-c' 2

  echo $(pwd)
  while true
  do
    read -p command
    echo "$command:" $command >> PID.cmd
 done
1
Contributor
2
Replies
3
Views
6 Years
Discussion Span
Last Post by mikeandike22
0

I currently only receive this output

command read: 10: arg count

what is not allowing me to input the commands.

0

Ok I made some progress not quite working all the way it doesnt like my bashtrap or incremental index

#!/bin/sh
    index=0
    trap bashtrap INT
    bashtrap(){
         echo "CTRL+C aborting bash script"
    }
    echo "starting to log"
    while : 
    do
        read -p "command:" inputline
        if [ $inputline="exit" ]
        then
                echo "Aborting with Exit"
                break
        else
                echo "$index: $inputline" > output
                $inputline 2>&1 | tee output
                (( index++ ))   
        fi
    done
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.