script: add --log-in
Let's allow to log input independently on output. So it's possible to script --log-in infile : logs only input script --log-out outfile : logs only output script --log-out outfile --log-in infile : logs both to separated files Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
fc58044f79
commit
70062aad13
|
@ -87,9 +87,17 @@ being done using `cat foo'.
|
||||||
Allow the default output destination, i.e. the typescript file, to be a hard
|
Allow the default output destination, i.e. the typescript file, to be a hard
|
||||||
or symbolic link. The command will follow a symbolic link.
|
or symbolic link. The command will follow a symbolic link.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-I\fR, \fB\-\-log\-in\fR \fIfile\fR
|
||||||
|
Log input to the \fIfile\fR. The log output is disabled if only \fB\-\-log\-in\fR
|
||||||
|
specified.
|
||||||
|
.sp
|
||||||
|
Use this logging functionality carefully as it logs all input, including input
|
||||||
|
when terminal has disabled echo flag (for example it log passwords in the input).
|
||||||
|
.TP
|
||||||
\fB\-O\fR, \fB\-\-log\-out\fR \fIfile\fR
|
\fB\-O\fR, \fB\-\-log\-out\fR \fIfile\fR
|
||||||
Log output to the \fIfile\fR. The default is to log the file with name 'typescript'
|
Log output to the \fIfile\fR. The default is to log output to the file with
|
||||||
if the option is not given.
|
name 'typescript' if the option \fB\-\-log\-out\fR or \fB\-\-log\-in\fR is not
|
||||||
|
given. The log output is disabled if only \fB\-\-log\-in\fR specified.
|
||||||
.TP
|
.TP
|
||||||
\fB\-T\fR, \fB\-\-log\-timing\fR \fIfile\fR
|
\fB\-T\fR, \fB\-\-log\-timing\fR \fIfile\fR
|
||||||
Log timing information to the \fIfile\fR.
|
Log timing information to the \fIfile\fR.
|
||||||
|
|
|
@ -189,6 +189,7 @@ static void __attribute__((__noreturn__)) usage(void)
|
||||||
fputs(_("Make a typescript of a terminal session.\n"), out);
|
fputs(_("Make a typescript of a terminal session.\n"), out);
|
||||||
|
|
||||||
fputs(USAGE_OPTIONS, out);
|
fputs(USAGE_OPTIONS, out);
|
||||||
|
fputs(_(" -I, --log-in <file> log stdin to file\n"), out);
|
||||||
fputs(_(" -O, --log-out <file> log stdout to file (default)\n"), out);
|
fputs(_(" -O, --log-out <file> log stdout to file (default)\n"), out);
|
||||||
fputs(_(" -T, --log-timing <file> log timing information to file\n"), out);
|
fputs(_(" -T, --log-timing <file> log timing information to file\n"), out);
|
||||||
fputs(_(" -a, --append append the output\n"), out);
|
fputs(_(" -a, --append append the output\n"), out);
|
||||||
|
@ -887,7 +888,7 @@ int main(int argc, char **argv)
|
||||||
.poll_timeout = -1
|
.poll_timeout = -1
|
||||||
};
|
};
|
||||||
int ch;
|
int ch;
|
||||||
const char *typescript = DEFAULT_TYPESCRIPT_FILENAME;
|
const char *outfile = NULL, *infile = NULL;
|
||||||
const char *timingfile = NULL;
|
const char *timingfile = NULL;
|
||||||
|
|
||||||
enum { FORCE_OPTION = CHAR_MAX + 1 };
|
enum { FORCE_OPTION = CHAR_MAX + 1 };
|
||||||
|
@ -898,6 +899,7 @@ int main(int argc, char **argv)
|
||||||
{"return", no_argument, NULL, 'e'},
|
{"return", no_argument, NULL, 'e'},
|
||||||
{"flush", no_argument, NULL, 'f'},
|
{"flush", no_argument, NULL, 'f'},
|
||||||
{"force", no_argument, NULL, FORCE_OPTION,},
|
{"force", no_argument, NULL, FORCE_OPTION,},
|
||||||
|
{"log-in", required_argument, NULL, 'I'},
|
||||||
{"log-out", required_argument, NULL, 'O'},
|
{"log-out", required_argument, NULL, 'O'},
|
||||||
{"log-timing", required_argument, NULL, 'T'},
|
{"log-timing", required_argument, NULL, 'T'},
|
||||||
{"output-limit", required_argument, NULL, 'o'},
|
{"output-limit", required_argument, NULL, 'o'},
|
||||||
|
@ -927,7 +929,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
script_init_debug();
|
script_init_debug();
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, "ac:efO:o:qT:t::Vh", longopts, NULL)) != -1) {
|
while ((ch = getopt_long(argc, argv, "ac:efI:O:o:qT:t::Vh", longopts, NULL)) != -1) {
|
||||||
|
|
||||||
err_exclusive_options(ch, longopts, excl, excl_st);
|
err_exclusive_options(ch, longopts, excl, excl_st);
|
||||||
|
|
||||||
|
@ -947,8 +949,13 @@ int main(int argc, char **argv)
|
||||||
case FORCE_OPTION:
|
case FORCE_OPTION:
|
||||||
ctl.force = 1;
|
ctl.force = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'I':
|
||||||
|
log_associate(&ctl, &ctl.in, optarg, SCRIPT_FMT_RAW);
|
||||||
|
infile = optarg;
|
||||||
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
typescript = optarg;
|
log_associate(&ctl, &ctl.out, optarg, SCRIPT_FMT_RAW);
|
||||||
|
outfile = optarg;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
ctl.maxsz = strtosize_or_err(optarg, _("failed to parse output limit size"));
|
ctl.maxsz = strtosize_or_err(optarg, _("failed to parse output limit size"));
|
||||||
|
@ -980,15 +987,18 @@ int main(int argc, char **argv)
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
if (!typescript) {
|
/* default if no --log-* specified */
|
||||||
|
if (!outfile && !infile) {
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
typescript = argv[0];
|
outfile = argv[0];
|
||||||
else
|
else {
|
||||||
die_if_link(&ctl, DEFAULT_TYPESCRIPT_FILENAME);
|
die_if_link(&ctl, DEFAULT_TYPESCRIPT_FILENAME);
|
||||||
}
|
outfile = DEFAULT_TYPESCRIPT_FILENAME;
|
||||||
|
}
|
||||||
|
|
||||||
/* associate stdout with typescript file */
|
/* associate stdout with typescript file */
|
||||||
log_associate(&ctl, &ctl.out, typescript, SCRIPT_FMT_RAW);
|
log_associate(&ctl, &ctl.out, outfile, SCRIPT_FMT_RAW);
|
||||||
|
}
|
||||||
|
|
||||||
ctl.shell = getenv("SHELL");
|
ctl.shell = getenv("SHELL");
|
||||||
if (ctl.shell == NULL)
|
if (ctl.shell == NULL)
|
||||||
|
@ -996,11 +1006,14 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
getmaster(&ctl);
|
getmaster(&ctl);
|
||||||
if (!ctl.quiet) {
|
if (!ctl.quiet) {
|
||||||
if (!timingfile)
|
printf(_("Script started"));
|
||||||
printf(_("Script started, log file is '%s'.\n"), typescript);
|
if (outfile)
|
||||||
else
|
printf(_(", output log file is '%s'"), outfile);
|
||||||
printf(_("Script started, log file is '%s', timing file is '%s'.\n"),
|
if (infile)
|
||||||
typescript, timingfile);
|
printf(_(", input log file is '%s'"), infile);
|
||||||
|
if (timingfile)
|
||||||
|
printf(_(", timing file is '%s'"), timingfile);
|
||||||
|
printf(_(".\n"));
|
||||||
}
|
}
|
||||||
enable_rawmode_tty(&ctl);
|
enable_rawmode_tty(&ctl);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue