-.\" $OpenBSD: script.1,v 1.14 2012/01/15 20:06:40 schwarze Exp $
+.\" $OpenBSD: script.1,v 1.15 2018/01/21 20:18:20 jasper Exp $
.\" $NetBSD: script.1,v 1.3 1994/12/21 08:55:41 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\"
.\" @(#)script.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: January 15 2012 $
+.Dd $Mdocdate: January 21 2018 $
.Dt SCRIPT 1
.Os
.Sh NAME
.Sh SYNOPSIS
.Nm script
.Op Fl a
+.Op Fl c Ar command
.Op Ar file
.Sh DESCRIPTION
.Nm
or
.Pa typescript ,
retaining the prior contents.
+.It Fl c Ar command
+Run
+.Ar command
+instead of an interactive shell.
+To run a command with arguments, enclose both in quotes.
.El
.Pp
-The script ends when the forked shell exits (a control-D
+The script ends when the forked program exits (a control-D
.Pq Ql ^D
to exit
the Bourne shell
If not set, the Bourne shell is assumed.
(Most shells set this variable automatically.)
.El
+.Sh EXAMPLES
+Start a virtual machine and log all console output to a file:
+.Bd -literal -offset indent
+$ script -c "vmctl start myvm -c" myvm.typescript
+.Ed
.Sh HISTORY
A predecessor called
.Nm dribble
-/* $OpenBSD: script.c,v 1.33 2017/04/12 14:49:05 deraadt Exp $ */
+/* $OpenBSD: script.c,v 1.34 2018/01/21 20:18:20 jasper Exp $ */
/* $NetBSD: script.c,v 1.3 1994/12/21 08:55:43 jtc Exp $ */
/*
__dead void done(int);
void dooutput(void);
-void doshell(void);
+void doshell(char *);
void fail(void);
void finish(int);
void scriptflush(int);
struct sigaction sa;
struct winsize win;
char ibuf[BUFSIZ];
+ char *cmd;
ssize_t cc, off;
int aflg, ch;
+ cmd = NULL;
aflg = 0;
- while ((ch = getopt(argc, argv, "a")) != -1)
+ while ((ch = getopt(argc, argv, "ac:")) != -1)
switch(ch) {
case 'a':
aflg = 1;
break;
+ case 'c':
+ cmd = optarg;
+ break;
default:
- fprintf(stderr, "usage: %s [-a] [file]\n", __progname);
+ fprintf(stderr, "usage: %s [-a] [-c command] [file]\n",
+ __progname);
exit(1);
}
argc -= optind;
if (child)
dooutput();
else
- doshell();
+ doshell(cmd);
}
bzero(&sa, sizeof sa);
done(sigdeadstatus);
}
-/* ARGSUSED */
void
finish(int signo)
{
errno = save_errno;
}
-/* ARGSUSED */
void
handlesigwinch(int signo)
{
done(0);
}
-/* ARGSUSED */
void
scriptflush(int signo)
{
}
void
-doshell(void)
+doshell(char *cmd)
{
char *shell;
+ char *argp[] = {"sh", "-c", NULL, NULL};
shell = getenv("SHELL");
if (shell == NULL)
(void)close(master);
(void)fclose(fscript);
login_tty(slave);
- execl(shell, shell, "-i", (char *)NULL);
- warn("%s", shell);
+
+ if (cmd != NULL) {
+ argp[2] = cmd;
+ execv(_PATH_BSHELL, argp);
+ warn("unable to execute %s", _PATH_BSHELL);
+ } else {
+ execl(shell, shell, "-i", (char *)NULL);
+ warn("%s", shell);
+ }
fail();
}