diff options
| author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1998-03-08 12:12:16 +0000 | 
|---|---|---|
| committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1998-03-08 12:12:16 +0000 | 
| commit | 4cb6b0566a5e80670a44ab6a4935241fe6c243ee (patch) | |
| tree | 8a11b23111a42a8932d01b747ee87938d53a6e02 | |
| parent | 88efa09f14a8c405bc90f562ed1cc6b46606272f (diff) | |
Notes
| -rw-r--r-- | usr.bin/script/script.1 | 17 | ||||
| -rw-r--r-- | usr.bin/script/script.c | 40 | 
2 files changed, 43 insertions, 14 deletions
diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1 index 7c1032f0509f..6c0f7d697ea7 100644 --- a/usr.bin/script/script.1 +++ b/usr.bin/script/script.1 @@ -30,6 +30,7 @@  .\" SUCH DAMAGE.  .\"  .\"	@(#)script.1	8.1 (Berkeley) 6/6/93 +.\"	$Id$  .\"  .Dd June 6, 1993  .Dt SCRIPT 1 @@ -40,7 +41,9 @@  .Sh SYNOPSIS  .Nm  .Op Fl a +.Op Fl q  .Op Ar file +.Op Ar command ...  .Sh DESCRIPTION  .Nm Script  makes a typescript of everything printed on your terminal. @@ -58,6 +61,13 @@ saves all dialogue in  If no file name is given, the typescript is saved in the file  .Pa typescript  .  .Pp +If the argument +.Ar command ... +is given, +.Nm +will run the specified command with an optional argument vector  +instead of an interactive shell. +.Pp  Option:  .Bl -tag -width Ds  .It Fl a @@ -66,9 +76,11 @@ Append the output to  or  .Pa typescript ,  retaining the prior contents. +.It Fl q +Run in quiet mode, omit the start and stop status messages.  .El  .Pp -The script ends when the forked shell exits (a +The script ends when the forked shell (or command) exits (a  .Em control-D  to exit  the Bourne shell @@ -121,3 +133,6 @@ places  .Sy everything  in the log file, including linefeeds and backspaces.  This is not what the naive user expects. +.Pp +It is not possible to specify a command without also naming the script file +because of argument parsing compatability issues. diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 18931b7cffeb..7bfa190546fb 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -42,7 +42,7 @@ static const char copyright[] =  static char sccsid[] = "@(#)script.c	8.1 (Berkeley) 6/6/93";  #endif  static const char rcsid[] = -	"$Id: script.c,v 1.3.2.1 1997/08/11 07:17:45 charnier Exp $"; +	"$Id: script.c,v 1.3.2.2 1997/08/29 05:29:52 imp Exp $";  #endif /* not lint */  #include <sys/types.h> @@ -67,12 +67,13 @@ int	master, slave;  int	child, subchild;  int	outcc;  char	*fname; +int	qflg;  struct	termios tt;  void	done __P((void)) __dead2;  void	dooutput __P((void)); -void	doshell __P((void)); +void	doshell __P((char **));  void	fail __P((void));  void	finish __P((int));  void	scriptflush __P((int)); @@ -90,11 +91,14 @@ main(argc, argv)  	char ibuf[BUFSIZ];  	aflg = 0; -	while ((ch = getopt(argc, argv, "a")) !=  -1) +	while ((ch = getopt(argc, argv, "aq")) != -1)  		switch(ch) {  		case 'a':  			aflg = 1;  			break; +		case 'q': +			qflg = 1; +			break;  		case '?':  		default:  			usage(); @@ -102,9 +106,11 @@ main(argc, argv)  	argc -= optind;  	argv += optind; -	if (argc > 0) +	if (argc > 0) {  		fname = argv[0]; -	else +		argv++; +		argc--; +	} else  		fname = "typescript";  	if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) @@ -115,7 +121,8 @@ main(argc, argv)  	if (openpty(&master, &slave, NULL, &tt, &win) == -1)  		err(1, "openpty"); -	(void)printf("Script started, output file is %s\n", fname); +	if (!qflg) +		(void)printf("Script started, output file is %s\n", fname);  	rtt = tt;  	cfmakeraw(&rtt);  	rtt.c_lflag &= ~ECHO; @@ -136,7 +143,7 @@ main(argc, argv)  		if (child)  			dooutput();  		else -			doshell(); +			doshell(argv);  	}  	(void)fclose(fscript); @@ -148,7 +155,7 @@ main(argc, argv)  static void  usage()  { -	(void)fprintf(stderr, "usage: script [-a] [file]\n"); +	(void)fprintf(stderr, "usage: script [-a] [-q] [file] [command]\n");  	exit(1);  } @@ -178,7 +185,8 @@ dooutput()  	(void)close(STDIN_FILENO);  	tvec = time(NULL); -	(void)fprintf(fscript, "Script started on %s", ctime(&tvec)); +	if (!qflg) +		(void)fprintf(fscript, "Script started on %s", ctime(&tvec));  	(void)signal(SIGALRM, scriptflush);  	value.it_interval.tv_sec = 60 / 2; @@ -207,7 +215,8 @@ scriptflush(signo)  }  void -doshell() +doshell(av) +	char **av;  {  	char *shell; @@ -218,7 +227,10 @@ doshell()  	(void)close(master);  	(void)fclose(fscript);  	login_tty(slave); -	execl(shell, "sh", "-i", NULL); +	if (av[0]) +		execvp(av[0], av); +	else +		execl(shell, "sh", "-i", NULL);  	warn(shell);  	fail();  } @@ -238,12 +250,14 @@ done()  	if (subchild) {  		tvec = time(NULL); -		(void)fprintf(fscript,"\nScript done on %s", ctime(&tvec)); +		if (!qflg) +			(void)fprintf(fscript,"\nScript done on %s", ctime(&tvec));  		(void)fclose(fscript);  		(void)close(master);  	} else {  		(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt); -		(void)printf("Script done, output file is %s\n", fname); +		if (!qflg) +			(void)printf("Script done, output file is %s\n", fname);  	}  	exit(0);  }  | 
