* script - makes copy of terminal conversation. usage:
* script [ -n ] [ -s ] [ -q ] [ -a ] [ -S shell ] [ file ]
* conversation saved in file. default is DFNAME
#define DFNAME "typescript"
#define STDSHELL "/bin/sh"
#define NEWSHELL "/p4/3723mrh/bin/csh"
#define STDSHELL "/bin/sh"
#define NEWSHELL "/t1/bruce/ucb/bin/csh"
#define STDSHELL "/bin/sh"
#define NEWSHELL "/bin/csh"
#define STDSHELL "/bin/sh"
#define NEWSHELL "/bin/csh"
/* used for version 7 with environments - gets your environment shell */
#define STDSHELL "/bin/sh"
#define NEWSHELL "/bin/csh"
char *shell
; /* initialized in the code */
* The following is the structure of the block returned by
* the stat and fstat system calls.
char i_minor
; /* +0: minor device of i-node */
char i_major
; /* +1: major device */
int i_flags
; /* +4: see below */
char i_nlinks
; /* +6: number of links to file */
char i_uid
; /* +7: user ID of owner */
char i_gid
; /* +8: group ID of owner */
char i_size0
; /* +9: high byte of 24-bit size */
int i_size1
; /* +10: low word of 24-bit size */
int i_addr
[8]; /* +12: block numbers or device number */
int i_actime
[2]; /* +28: time of last access */
int i_modtime
[2]; /* +32: time of last modification */
char *tty
; /* name of users tty so can turn off writes */
char *ttyname(); /* std subroutine */
int mode
= 0622; /* old permission bits for users tty */
int outpipe
[2]; /* pipe from shell to output */
int fd
; /* file descriptor of typescript file */
int inpipe
[2]; /* pipe from input to shell */
long tvec
; /* current time */
char buffer
[256]; /* for block I/O's */
int n
; /* number of chars read */
int status
; /* dummy for wait sys call */
char *fname
; /* name of typescript file */
int forkval
, ttn
; /* temps for error checking */
int qflg
; /* true if -q (quiet) flag */
int aflg
; /* true if -q (append) flag */
main(argc
,argv
) int argc
; char **argv
; {
if ((tty
= ttyname(2)) < 0) {
printf("Nested script not allowed.\n");
while ( argc
> 1 && argv
[1][0] == '-') {
printf("Bad flag %s - ignored\n",argv
[1]);
if (!aflg
&& stat(fname
,&sbuf
) >= 0) {
printf("File %s already exists.\n",fname
);
fd
= creat(fname
,0); /* so can't cat/lpr typescript from inside */
/* try to append to existing file first */
if (fd
>= 0) lseek(fd
,0l,2);
else fd
= creat(fname
,0);
printf("Can't create %s\n",fname
);
printf("because of previous typescript bomb - try again\n");
chmod(fname
,0); /* in case it already exists */
printf("Script started, file is %s\n",fname
);
check(write(fd
,"Script started on ",18));
check(write(fd
,ctime(&tvec
),25));
printf("Fork failed - try again.\n");
if (forkval
== 0) doshell();
printf("Fork failed. Try again.\n");
if (forkval
== 0) dooutput();
/* input process - copy tty to pipe and file */
signal(2,1); /* ignore interrupts from delete */
signal(3,done
); /* fix files when users quits. */
/* main input loop - copy until end of file (ctrl D) */
while (n
=read(0,buffer
,256)) {
check(write(fd
,buffer
,n
));
write(inpipe
[1],buffer
,n
);
/* end of script - close files and exit */
wait(&status
); /* wait for shell to terminate */
wait(&status
); /* wait for output to terminate */
/* do output process - copy to tty & file */
signal(2,flsh
); /* trap to flsh on interrupts */
signal(3,1); /* ignore quits */
/* main output proc loop */
while (n
=read(outpipe
[0],buffer
,256)) {
if (n
> 0) { /* -1 means trap to flsh just happened */
check(write(fd
,buffer
,n
));
/* output sees eof - close files and exit */
printf("Script done, file is %s\n",fname
);
check(write(fd
,"\nscript done on ",16));
check(write(fd
,ctime(&tvec
),25));
/* exec shell, after divirting std input & output */
/* close useless files */
/* signal(2,1); /* shell should ignore interrupts */
execl(shell
,"sh","-i",0);
execl(STDSHELL
,"sh","-i",0);
execl(NEWSHELL
,"sh","-i",0);
printf("Can't execute shell\n");
/* come here on rubout to flush output - this doesn't work */
/* lseek(outpipe[0],0l,2); /* seeks on pipes don't work !"$"$!! */
kill(0,15); /* shut off other script processes */
char *ttyname(i
) int i
; {
if (string
[8] == 'x') return((char *) (-1));
/* checks the result of a write call, if neg
assume ran out of disk space & die */
write(1,"Disk quota exceeded - script quits\n",35);