dear unix wizards: I have wrestled with the unix script program for a while, but to no avail. It may be the wrong program altogether, but googling is hard, because script usually just means sh or bash script. my question is easy to explain with an example.

let's say I have the following input file testscript.scr:

# cat testscript.scr
100 200 * f
exit  ## well, from scripting

the result should be a log file that contains all the results as if I had typed in each line, waited for the output, then typed the next line, etc.:

sh-3.2$ date
Wed Feb 28 10:09:14 PST 2018
sh-3.2$ dc
100 200 * f
sh-3.2$ date
Wed Feb 28 10:09:24 PST 2018

I only want to see the input where it would occur, I want it to be followed by the output, and I want this to work with child processes, too. the script input in effect should simulate (and log) keyboard input whenever the running programs has blocked to await input.

when I try to run commands like script -k -t 2 outfile.log sh < testscript.scr, it surely does not like this. instead, it repeats the input queue after each program response.

how does one do this?

  • In the case of dc, the user isn't waiting for any output before proceeding to send input. How would you handle that case if you were writing a program to decide when to send the input? – Mark Plotnick Feb 28 '18 at 22:51
  • whenever the current program blocks (expects input), you feed it another character. – ivo Welch Mar 1 '18 at 22:31
  • I don't have a solution but remember having this issue a while ago, typing the commands directly has the proper order but input from a file mixes it up (we ended up doing something else altogether so i never solved it). However, there is a derivative from script called ttyrec ( 0xcc.net/ttyrec ) and more derivatives from this. When i was testing it, ttyrec had the same problem however, just wanted to leave this info here as "ttyrec" is much easier to search online than "script". Also there is termrec and playitagainsam, both inspired (but not derived, afaik) by script. – canofcolliders Mar 3 '18 at 21:27
  • another typical "goto" solution seems to be the Unix "expect" program, and a perl module that tries to offer some of this functionality. – ivo Welch Mar 5 '18 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.