1996-11-27 15:52:01 -04:00
|
|
|
#! /usr/bin/env python
|
2009-10-11 09:00:18 -03:00
|
|
|
|
1994-10-03 13:45:35 -03:00
|
|
|
# script.py -- Make typescript of terminal session.
|
|
|
|
# Usage:
|
2004-07-18 02:56:09 -03:00
|
|
|
# -a Append to typescript.
|
|
|
|
# -p Use Python as shell.
|
1994-10-03 13:45:35 -03:00
|
|
|
# Author: Steen Lumholt.
|
|
|
|
|
|
|
|
|
2009-10-11 09:00:18 -03:00
|
|
|
import os, time, sys, getopt
|
1994-10-03 13:45:35 -03:00
|
|
|
import pty
|
|
|
|
|
|
|
|
def read(fd):
|
2004-07-18 02:56:09 -03:00
|
|
|
data = os.read(fd, 1024)
|
2009-10-11 09:03:01 -03:00
|
|
|
script.write(data)
|
2004-07-18 02:56:09 -03:00
|
|
|
return data
|
1994-10-03 13:45:35 -03:00
|
|
|
|
|
|
|
shell = 'sh'
|
|
|
|
filename = 'typescript'
|
|
|
|
mode = 'w'
|
|
|
|
if os.environ.has_key('SHELL'):
|
2004-07-18 02:56:09 -03:00
|
|
|
shell = os.environ['SHELL']
|
1994-10-03 13:45:35 -03:00
|
|
|
|
2009-10-11 09:00:18 -03:00
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], 'ap')
|
|
|
|
except getopt.error, msg:
|
|
|
|
print '%s: %s' % (sys.argv[0], msg)
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
for o, a in opts:
|
|
|
|
if o == '-a':
|
|
|
|
mode = 'a'
|
|
|
|
elif o == '-p':
|
|
|
|
shell = 'python'
|
|
|
|
|
|
|
|
script = open(filename, mode)
|
1994-10-03 13:45:35 -03:00
|
|
|
|
|
|
|
sys.stdout.write('Script started, file is %s\n' % filename)
|
2009-10-11 09:00:18 -03:00
|
|
|
script.write('Script started on %s\n' % time.ctime(time.time()))
|
1994-10-03 13:45:35 -03:00
|
|
|
pty.spawn(shell, read)
|
2009-10-11 09:00:18 -03:00
|
|
|
script.write('Script done on %s\n' % time.ctime(time.time()))
|
1994-10-03 13:45:35 -03:00
|
|
|
sys.stdout.write('Script done, file is %s\n' % filename)
|