unixcsh

How to redirect output from interactive script to file and console?


I have a complex interactive script working with version control software (clearcase).

User selects / types the options based on the script's prompt.

The goal is to save everything (script output, prompts and user input) to a file for further processing. For example, line

perlscript | tee output.tmp

displays the first two prints from a perl script, then (probably at the time of extracting information from the version control system) execution stops (nothing happens) and nothing is written to the file. The shell is csh.

Is it possible to do without updating / extending perlscript?


Solution

  • You can use the script command to capture a log of the entire session.

    Just type:

     script <logfilename> 
    

    Before running your script as normal. When you have finished type exit to close the log file.

    If you want to incorporate this into your script you can make a wrapper script to run it like this:

    #!/bin/bash
    script "My_logfile" my_script
    

    This will create the log file and run my_script. When the script ends the log file will be closed.