#!/bin/sh
# \
exec expectk -f "$0" ${1+"$@"}
#
# NAME
#	multixterm - drive multiple xterms separately or together
#
# SYNOPSIS
#	multixterm [-xa "xterm args"]
#		   [-xc "command"]
#		   [-xd "directory"]
#		   [-xf "file"]
#		   [-xn "xterm names"]
#		   [-xv] (enable verbose mode)
#		   [-xh] or [-x?] (help)
#		   [xterm names or user-defined args...]
#
# DESCRIPTION
#	Multixterm creates multiple xterms that can be driven together
#	or separately.
#
#	In its simplest form, multixterm is run with no arguments and
#	commands are interactively entered in the first entry field.
#	Press return (or click the "new xterm" button) to create a new
#	xterm running that command.
#
#	Keystrokes in the "stdin window" are redirected to all xterms
#	started by multixterm.  xterms may be driven separately simply
#	by focusing on them.
#
#	The stdin window must have the focus for keystrokes to be sent
#	to the xterms.  When it has the focus, the color changes to
#	aquamarine.  As characters are entered, the color changes to
#	green for a second.  This provides feedback since characters
#	are not echoed in the stdin window.
#
#	Typing in the stdin window while holding down the alt or meta
#	keys sends an escape character before the typed characters.
#	This provides support for programs such as emacs.
#
# ARGUMENTS
#	The optional -xa argument indicates arguments to pass to
#	xterm.
#
#	The optional -xc argument indicates a command to be run in
#	each named xterm (see -xn).  With no -xc argument, the command
#	is the current shell.
#
#	The optional -xd argument indicates a directory to search for
#	files that will appear in the Files menu.  By default, the
#	directory is: ~/lib/multixterm
#
#	The optional -xf argument indicates a file to be read at
#	startup.  See FILES below for more info.
#
#	The optional -xn argument indicates a name for each xterm.
#	This name will also be substituted for any %n in the command
#	argument (see -xc).
#
#	The optional -xv flag puts multixterm into a verbose mode
#	where it will describe some of the things it is doing
#	internally.  The verbose output is not intended to be
#	understandable to anyone but the author.
#
#	Less common options may be changed by the startup file (see
#	FILES below).
#
#	All the usual X and wish flags are supported (i.e., -display,
#	-name).  There are so many of them that to avoid colliding and
#	make them easy to remember, all the multixterm flags begin
#	with -x.
#
#	If any arguments do not match the flags above, the remainder
#	of the command line is made available for user processing.  By
#	default, the remainder is used as a list of xterm names in the
#	style of -xn. The default behavior may be changed using the
#	.multixtermrc file (see DOT FILE below).
#
# EXAMPLE COMMAND LINE ARGUMENTS
#	The following command line starts up two xterms using ssh to
#	the hosts bud and dexter.
#
#		multixterm -xc "ssh %n" bud dexter
#
# FILES
#	Command files may be used to drive or initializurn to kibitzing, enter: return\n"
	interpreter
	send_user "returning to kibitz\n"
      }
   }
}

proc prompt1 {} {
    return "kibitz[info level].[history nextid]> "
}

set timeout -1

# kibitzer executes following code
if {$user_number==2} {
    # for readability, swap variables
    set tmp $userinfile
    set userinfile $useroutfile
    set useroutfile $tmp

    if ![file readable $userinfile] {
	send_user "Eh?  No one is asking you to kibitz.\n"
	exit -1
    }
    spawn -open [open "|cat $catflags < $userinfile" "r"]
    set userin $spawn_id

    spawn -open [open $useroutfile w]
    set userout $spawn_id
    # open will hang until other user's cat starts

    stty -echo raw
    if {$allow_escape} {send_user "Escape sequence is $escape_printable\r\n"}

    # While user is reading message, try to delete other fifo
    catch {exec rm -f $userinfile}

    eval interact $esc_match \
	    -output $userout \
	    -input $userin

    exit
}

# only user_numbers 1 and 3 execute remaining code

proc abort {} {
    # KABORT tells user_number 1 that user_number 3 has run into problems
    # and is exiting, and diagnostics have been returned already
    if {$::user_number==3} {send_user KABORT}
    exit
}

if {$local_io} {
    proc mkfifo {f} {
	if 0==[catch {exec mkfifo $f}] return		;# POSIX
	if 0==[catch {exec mknod $f p}] return
	# some systems put mknod in wierd places
	if 0==[catch {exec /usr/etc/mknod $f p}] return	;# Sun
	if 0==[catch {exec /etc/mknod $f p}] return	;# AIX, Cray
	puts "Couldn't figure out how to make a fifo - where is mknod?"
	abort
    }

    proc rmfifos {} {
	global userinfile useroutfile
	catch {exec rm -f $userinfile $useroutfile}
    }

    trap {rmfifos; exit} {SIGINT SIGQUIT SIGTERM}

    # create 2 fifos to communicate with other user
    mkfifo $userinfile
    mkfifo $useroutfile
    # make sure other user can access despite umask
    exec chmod 666 $userinfile $useroutfile

    if {$verbose} {send_user "asking $user to type:  kibitz -$pid\n"}

    # can't use exec since write insists on being run from a tty!
    set rc [catch {
		   system echo "Can we talk?  Run: \"kibitz -$pid\"" | \
			write $user $tty
		}
	]
    if {$rc} {rmfifos;abort}

    spawn -open [open $useroutfile w]
    set userout $spawn_id
    # open will hang until other user's cat starts

    spawn -open [open "|cat $catflags < $userinfile" "r"]
    set userin $spawn_id
    catch {exec rm $userinfile}
}

stty -echo raw

if {$user_number==3} {
    send_user "KDATA"	;# this tells user_number 1 to send data

    interact {
	-output $userout
	-input $userin eof {
	    wait -i $userin
	    return -tcl
	} -output $user_spawn_id 
    }
} else {
    if {$allow_escape} {send_user "Escape sequence is $escape_printable\r\n"}

    if {$noproc} {
	interact {
	    -output $userout
	    -input $userin eof {wait -i $userin; return}
	    -output $user_spawn_id
	}
    } else {
	eval interact $esc_match {
	    -output $shell \
		    -input $userin eof {
		wait -i $userin
		close -i $shell
		return
	    } -output $shell \
		    -input $shell eof {
		close -i $userout
		wait -i $userout
		return
	    } -output "$user_spawn_id $userout"
	}
	wait -i $shell
    }
}

if {$local_io} rmfifos
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ./usr/share/doc/expect-tcl8.3/examples/lpunlock                                                     0000755 0000000 0000000 00000004746 10403173722 020277  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/sh
# \
exec expect -f "$0" ${1+"$@"}

# This script unhangs a printer which claims it is "waiting for lock".
# Written by Don Libes.  Based on English instructions from Scott Paisley.

# lpunlock figures out if the printer is on a server, and if so which,
# by looking in the local printcap file.  (You can override this by
# supplying a server name as an additional argument.)  It then rlogins
# to the server, recreates the device and resets the queue via lpc.

# assumes user has root privs on remote host via /.rhosts

# assumes printer is name of device on remote system

proc usage {} {
	send_user "usage: lpunlock <printer> \[<server>\]\n"
	send_user "example: lpunlock lw-isg durer\n"
	exit
}

if {$argc==0} usage
set printer [lindex $argv 0]

set client [exec hostname]

if {$argc == 1} {
	# if no arg2, look in local printcap for info
	spawn ed /etc/printcap
	expect "\n"			;# discard character count
	send "/$printer/\r"
	for {} {1} {} {
		expect -re ".*:rm=(\[^:]*):.*\r\n" {
			set server $expect_out(1,string)
			break
		} "\r\n*\\\r\n" {	;# look at next line of entry
			send "\r"
		} "\r\n*\n" {		;# no more lines of entry - give up
			set server $client
			break
		}
	}
} else {
	if {$argc == 2} {
		set server [lindex $argv 1]
	} else usage
}

set whoami [exec whoami]
if {[string match $server $client] && [string match $whoami "root"]} {
	spawn csh
	expect "# "
} else {
	# login to the print server as root.
	# Set timeout high because login is slow.
	set timeout 60
	spawn rlogin $server -l root
	expect	timeout	exit \
		eof exit \
		"Password*" {
			send_user "\ncouldn't login to $server as root\n"
			exit
		} "1#*"
	set timeout 10
}

# run lpc and 'stop printer'
send lpc\r				; expect "lpc>*"
send stop $printer\r			; expect "unknown*" exit \
						"disabled*lpc>*"

# exit lpc and cd /dev
send quit\r				; expect "#*"
send cd /dev\r				; expect "#*"

# figure out major/minor device numbers
send ls -l /dev/$printer\r		; expect timeout {
	send_user "\nbad device - couldn't get major/minor numbers\n"; exit
						} "crw*#*"
scan $expect_out(buffer) "ls -l %*s %*s 1 root %d, %d" major minor

# delete the lock and the printer device itself
send rm /var/spool/$printer/lock /dev/$printer\r	; expect #*

# recreate the printer device
send mknod $printer c $major $minor\r	; expect #*

# run lpc and 'start printer'
send lpc\r				; expect lpc>*
send start $printer\r			; expect started*lpc>*
send quit\r				; expect #*

# logout
send exit\r				; expect eof

send_user Printer unlocked and restarted.\n
                          ./usr/share/doc/expect-tcl8.3/examples/mkpasswd                                                     0000755 0000000 0000000 00000012267 10403173723 020277  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/sh
# \
exec expectk -f "$0" ${1+"$@"}
# mkpasswd - make a password, if username given, set it.
# Author: Don Libes, NIST

# defaults
set length 9
set minnum 2
set minlower 2
set minupper 2
set minspecial 1
set verbose 0
set distribute 0

if {[file executable /bin/nispasswd]} {
	set defaultprog /bin/nispasswd
} elseif {[file executable /bin/yppasswd]} {
	set defaultprog /bin/yppasswd
} elseif {[file executable /bin/passwd]} {
	set defaultprog /bin/passwd
} else {
	set defaultprog passwd
}
set prog $defaultprog

while {[llength $argv]>0} {
	set flag [lindex $argv 0]
	switch -- $flag \
	"-l" {
		set length [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-d" {
		set minnum [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-c" {
		set minlower [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-C" {
		set minupper [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-s" {
		set minspecial [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-v" {
		set verbose 1
		set argv [lrange $argv 1 end]
	} "-p" {
		set prog [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-2" {
		set distribute 1
		set argv [lrange $argv 1 end]
	} default {
		set user [lindex $argv 0]
		set argv [lrange $argv 1 end]
		break
	}
}

if {[llength $argv]} {
	puts "usage: mkpasswd \[args] \[user]"
	puts "  where arguments are:"
	puts "    -l #      (length of password, default = $length)"
	puts "    -d #      (min # of digits, default = $minnum)"
	puts "    -c #      (min # of lowercase chars, default = $minlower)"
	puts "    -C #      (min # of uppercase chars, default = $minupper)"
	puts "    -s #      (min # of special chars, default = $minspecial)"
	puts "    -v        (verbose, show passwd interaction)"
	puts "    -p prog   (program to set password, default = $defaultprog)"
	exit 1
}

if {$minnum + $minlower + $minupper + $minspecial > $length} {
	puts "impossible to generate $length-character password\
		with $minnum numbers, $minlower lowercase letters,\
		$minupper uppercase letters and\
		$minspecial special characters."
	exit 1
}

# if there is any underspecification, use additional lowercase letters
set minlower [expr {$length - ($minnum + $minupper + $minspecial)}]

set lpass ""		;# password chars typed by left hand
set rpass ""		;# password chars typed by right hand

# insert char into password at a random position, thereby spreading
# the different kinds of characters throughout the password
proc insert {pvar char} {
    upvar $pvar p

    set p [linsert $p [rand [expr {(1+[llength $p])}]] $char]
}

proc rand {m} {
    expr {int($m*rand())}
}

# choose left or right starting hand
set initially_left [set isleft [rand 2]]

# given a size, distribute between left and right hands
# taking into account where we left off
proc psplit {max lvar rvar} {
	upvar $lvar left $rvar right
	global isleft

	if {$isleft} {
		set right [expr $max/2]
		set left [expr $max-$right]
		set isleft [expr !($max%2)]
	} else {
		set left [expr $max/2]
		set right [expr $max-$left]
		set isleft [expr $max%2]
	}
}

if {$distribute} {
	set lkeys {q w e r t a s d f g z x c v b}
	set rkeys {y u i o p h j k l n m}
	set lnums {1 2 3 4 5 6}
	set rnums {7 8 9 0}
	set lspec {! @ # \$ %}
	set rspec {^ & * ( ) - = _ + [ ] "{" "}" \\ | ; : ' \" < > , . ? /}
} else {
	set lkeys {a b c d e f g h i j k l m n o p q r s t u v w x y z}
	set rkeys {a b c d e f g h i j k l m n o p q r s t u v w x y z}
	set lnums {0 1 2 3 4 5 6 7 8 9}
	set rnums {0 1 2 3 4 5 6 7 8 9}
	set lspec {! @ # \$ % ~ ^ & * ( ) - = _ + [ ] "{" "}" \\ | ; : ' \" < > , . ? /}
	set rspec {! @ # \$ % ~ ^ & * ( ) - = _ + [ ] "{" "}" \\ | ; : ' \" < > , . ? /}
}

set lkeys_length [llength $lkeys]
set rkeys_length [llength $rkeys]
set lnums_length [llength $lnums]
set rnums_length [llength $rnums]
set lspec_length [llength $lspec]
set rspec_length [llength $rspec]

psplit $minnum left right
for {set i 0} {$i<$left} {incr i} {
	insert lpass [lindex $lnums [rand $lnums_length]]
}
for {set i 0} {$i<$right} {incr i} {
	insert rpass [lindex $rnums [rand $rnums_length]]
}

psplit $minlower left right
for {set i 0} {$i<$left} {incr i} {
	insert lpass [lindex $lkeys [rand $lkeys_length]]
}
for {set i 0} {$i<$right} {incr i} {
	insert rpass [lindex $rkeys [rand $rkeys_length]]
}

psplit $minupper left right
for {set i 0} {$i<$left} {incr i} {
	insert lpass [string toupper [lindex $lkeys [rand $lkeys_length]]]
}
for {set i 0} {$i<$right} {incr i} {
	insert rpass [string toupper [lindex $rkeys [rand $rkeys_length]]]
}

psplit $minspecial left right
for {set i 0} {$i<$left} {incr i} {
	insert lpass [lindex $lspec [rand $lspec_length]]
}
for {set i 0} {$i<$right} {incr i} {
	insert rpass [lindex $rspec [rand $rspec_length]]
}

# merge results together
foreach l $lpass r $rpass {
    if {$initially_left} {
	append password $l $r
    } else {
	append password $r $l
    }
}

if {[info exists user]} {
	if {!$verbose} {
		log_user 0
	}

	spawn $prog $user
	expect {
		"assword*:" {
			# some systems say "Password (again):"
			send "$password\r"
			exp_continue
		}
	}

	# if user isn't watching, check status
	if {!$verbose} {
		if {[lindex [wait] 3]} {
			puts -nonewline "$expect_out(buffer)"
			exit 1
		}
	}

        if {$verbose} {
	    puts -nonewline "password for $user is "
        }
}

puts "$password"
                                                                                                                                                                                                                                                                                                                                         ./usr/share/doc/expect-tcl8.3/examples/multixterm                                                   0000755 0000000 0000000 00000073316 10403173723 020662  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/sh
# \
exec expectk -f "$0" ${1+"$@"}
#
# NAME
#	multixterm - drive multiple xterms separately or together
#
# SYNOPSIS
#	multixterm [-xa "xterm args"]
#		   [-xc "command"]
#		   [-xd "directory"]
#		   [-xf "file"]
#		   [-xn "xterm names"]
#		   [-xv] (enable verbose mode)
#		   [-xh] or [-x?] (help)
#		   [xterm names or user-defined args...]
#
# DESCRIPTION
#	Multixterm creates multiple xterms that can be driven together
#	or separately.
#
#	In its simplest form, multixterm is run with no arguments and
#	commands are interactively entered in the first entry field.
#	Press return (or click the "new xterm" button) to create a new
#	xterm running that command.
#
#	Keystrokes in the "stdin window" are redirected to all xterms
#	started by multixterm.  xterms may be driven separately simply
#	by focusing on them.
#
#	The stdin window must have the focus for keystrokes to be sent
#	to the xterms.  When it has the focus, the color changes to
#	aquamarine.  As characters are entered, the color changes to
#	green for a second.  This provides feedback since characters
#	are not echoed in the stdin window.
#
#	Typing in the stdin window while holding down the alt or meta
#	keys sends an escape character before the typed characters.
#	This provides support for programs such as emacs.
#
# ARGUMENTS
#	The optional -xa argument indicates arguments to pass to
#	xterm.
#
#	The optional -xc argument indicates a command to be run in
#	each named xterm (see -xn).  With no -xc argument, the command
#	is the current shell.
#
#	The optional -xd argument indicates a directory to search for
#	files that will appear in the Files menu.  By default, the
#	directory is: ~/lib/multixterm
#
#	The optional -xf argument indicates a file to be read at
#	startup.  See FILES below for more info.
#
#	The optional -xn argument indicates a name for each xterm.
#	This name will also be substituted for any %n in the command
#	argument (see -xc).
#
#	The optional -xv flag puts multixterm into a verbose mode
#	where it will describe some of the things it is doing
#	internally.  The verbose output is not intended to be
#	understandable to anyone but the author.
#
#	Less common options may be changed by the startup file (see
#	FILES below).
#
#	All the usual X and wish flags are supported (i.e., -display,
#	-name).  There are so many of them that to avoid colliding and
#	make them easy to remember, all the multixterm flags begin
#	with -x.
#
#	If any arguments do not match the flags above, the remainder
#	of the command line is made available for user processing.  By
#	default, the remainder is used as a list of xterm names in the
#	style of -xn. The default behavior may be changed using the
#	.multixtermrc file (see DOT FILE below).
#
# EXAMPLE COMMAND LINE ARGUMENTS
#	The following command line starts up two xterms using ssh to
#	the hosts bud and dexter.
#
#		multixterm -xc "ssh %n" bud dexter
#
# FILES
#	Command files may be used to drive or initializurn to kibitzing, enter: return\n"
	interpreter
	send_user "returning to kibitz\n"
      }
   }
}

proc prompt1 {} {
    return "kibitz[info level].[history nextid]> "
}

set timeout -1

# kibitzer executes following code
if {$user_number==2} {
    # for readability, swap variables
    set tmp $userinfile
    set userinfile $useroutfile
    set useroutfile $tmp

    if ![file readable $userinfile] {
	send_user "Eh?  No one is asking you to kibitz.\n"
	exit -1
    }
    spawn -open [open "|cat $catflags < $userinfile" "r"]
    set userin $spawn_id

    spawn -open [open $useroutfile w]
    set userout $spawn_id
    # open will hang until other user's cat starts

    stty -echo raw
    if {$allow_escape} {send_user "Escape sequence is $escape_printable\r\n"}

    # While user is reading message, try to delete other fifo
    catch {exec rm -f $userinfile}

    eval interact $esc_match \
	    -output $userout \
	    -input $userin

    exit
}

# only user_numbers 1 and 3 execute remaining code

proc abort {} {
    # KABORT tells user_number 1 that user_number 3 has run into problems
    # and is exiting, and diagnostics have been returned already
    if {$::user_number==3} {send_user KABORT}
    exit
}

if {$local_io} {
    proc mkfifo {f} {
	if 0==[catch {exec mkfifo $f}] return		;# POSIX
	if 0==[catch {exec mknod $f p}] return
	# some systems put mknod in wierd places
	if 0==[catch {exec /usr/etc/mknod $f p}] return	;# Sun
	if 0==[catch {exec /etc/mknod $f p}] return	;# AIX, Cray
	puts "Couldn't figure out how to make a fifo - where is mknod?"
	abort
    }

    proc rmfifos {} {
	global userinfile useroutfile
	catch {exec rm -f $userinfile $useroutfile}
    }

    trap {rmfifos; exit} {SIGINT SIGQUIT SIGTERM}

    # create 2 fifos to communicate with other user
    mkfifo $userinfile
    mkfifo $useroutfile
    # make sure other user can access despite umask
    exec chmod 666 $userinfile $useroutfile

    if {$verbose} {send_user "asking $user to type:  kibitz -$pid\n"}

    # can't use exec since write insists on being run from a tty!
    set rc [catch {
		   system echo "Can we talk?  Run: \"kibitz -$pid\"" | \
			write $user $tty
		}
	]
    if {$rc} {rmfifos;abort}

    spawn -open [open $useroutfile w]
    set userout $spawn_id
    # open will hang until other user's cat starts

    spawn -open [open "|cat $catflags < $userinfile" "r"]
    set userin $spawn_id
    catch {exec rm $userinfile}
}

stty -echo raw

if {$user_number==3} {
    send_user "KDATA"	;# this tells user_number 1 to send data

    interact {
	-output $userout
	-input $userin eof {
	    wait -i $userin
	    return -tcl
	} -output $user_spawn_id 
    }
} else {
    if {$allow_escape} {send_user "Escape sequence is $escape_printable\r\n"}

    if {$noproc} {
	interact {
	    -output $userout
	    -input $userin eof {wait -i $userin; return}
	    -output $user_spawn_id
	}
    } else {
	eval interact $esc_match {
	    -output $shell \
		    -input $userin eof {
		wait -i $userin
		close -i $shell
		return
	    } -output $shell \
		    -input $shell eof {
		close -i $userout
		wait -i $userout
		return
	    } -output "$user_spawn_id $userout"
	}
	wait -i $shell
    }
}

if {$local_io} rmfifos
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ./usr/share/doc/expect-tcl8.3/examples/lpunlock                                                     0000755 0000000 0000000 00000004746 10403173722 020277  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/sh
# \
exec expect -f "$0" ${1+"$@"}

# This script unhangs a printer which claims it is "waiting for lock".
# Written by Don Libes.  Based on English instructions from Scott Paisley.

# lpunlock figures out if the printer is on a server, and if so which,
# by looking in the local printcap file.  (You can override this by
# supplying a server name as an additional argument.)  It then rlogins
# to the server, recreates the device and resets the queue via lpc.

# assumes user has root privs on remote host via /.rhosts

# assumes printer is name of device on remote system

proc usage {} {
	send_user "usage: lpunlock <printer> \[<server>\]\n"
	send_user "example: lpunlock lw-isg durer\n"
	exit
}

if {$argc==0} usage
set printer [lindex $argv 0]

set client [exec hostname]

if {$argc == 1} {
	# if no arg2, look in local printcap for info
	spawn ed /etc/printcap
	expect "\n"			;# discard character count
	send "/$printer/\r"
	for {} {1} {} {
		expect -re ".*:rm=(\[^:]*):.*\r\n" {
			set server $expect_out(1,string)
			break
		} "\r\n*\\\r\n" {	;# look at next line of entry
			send "\r"
		} "\r\n*\n" {		;# no more lines of entry - give up
			set server $client
			break
		}
	}
} else {
	if {$argc == 2} {
		set server [lindex $argv 1]
	} else usage
}

set whoami [exec whoami]
if {[string match $server $client] && [string match $whoami "root"]} {
	spawn csh
	expect "# "
} else {
	# login to the print server as root.
	# Set timeout high because login is slow.
	set timeout 60
	spawn rlogin $server -l root
	expect	timeout	exit \
		eof exit \
		"Password*" {
			send_user "\ncouldn't login to $server as root\n"
			exit
		} "1#*"
	set timeout 10
}

# run lpc and 'stop printer'
send lpc\r				; expect "lpc>*"
send stop $printer\r			; expect "unknown*" exit \
						"disabled*lpc>*"

# exit lpc and cd /dev
send quit\r				; expect "#*"
send cd /dev\r				; expect "#*"

# figure out major/minor device numbers
send ls -l /dev/$printer\r		; expect timeout {
	send_user "\nbad device - couldn't get major/minor numbers\n"; exit
						} "crw*#*"
scan $expect_out(buffer) "ls -l %*s %*s 1 root %d, %d" major minor

# delete the lock and the printer device itself
send rm /var/spool/$printer/lock /dev/$printer\r	; expect #*

# recreate the printer device
send mknod $printer c $major $minor\r	; expect #*

# run lpc and 'start printer'
send lpc\r				; expect lpc>*
send start $printer\r			; expect started*lpc>*
send quit\r				; expect #*

# logout
send exit\r				; expect eof

send_user Printer unlocked and restarted.\n
                          ./usr/share/doc/expect-tcl8.3/examples/mkpasswd                                                     0000755 0000000 0000000 00000012267 10403173723 020277  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/sh
# \
exec expectk -f "$0" ${1+"$@"}
# mkpasswd - make a password, if username given, set it.
# Author: Don Libes, NIST

# defaults
set length 9
set minnum 2
set minlower 2
set minupper 2
set minspecial 1
set verbose 0
set distribute 0

if {[file executable /bin/nispasswd]} {
	set defaultprog /bin/nispasswd
} elseif {[file executable /bin/yppasswd]} {
	set defaultprog /bin/yppasswd
} elseif {[file executable /bin/passwd]} {
	set defaultprog /bin/passwd
} else {
	set defaultprog passwd
}
set prog $defaultprog

while {[llength $argv]>0} {
	set flag [lindex $argv 0]
	switch -- $flag \
	"-l" {
		set length [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-d" {
		set minnum [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-c" {
		set minlower [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-C" {
		set minupper [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-s" {
		set minspecial [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-v" {
		set verbose 1
		set argv [lrange $argv 1 end]
	} "-p" {
		set prog [lindex $argv 1]
		set argv [lrange $argv 2 end]
	} "-2" {
		set distribute 1
		set argv [lrange $argv 1 end]
	} default {
		set user [lindex $argv 0]
		set argv [lrange $argv 1 end]
		break
	}
}

if {[llength $argv]} {
	puts "usage: mkpasswd \[args] \[user]"
	puts "  where arguments are:"
	puts "    -l #      (length of password, default = $length)"
	puts "    -d #      (min # of digits, default = $minnum)"
	puts "    -c #      (min # of lowercase chars, default = $minlower)"
	puts "    -C #      (min # of uppercase chars, default = $minupper)"
	puts "    -s #      (min # of special chars, default = $minspecial)"
	puts "    -v        (verbose, show passwd interaction)"
	puts "    -p prog   (program to set password, default = $defaultprog)"
	exit 1
}

if {$minnum + $minlower + $minupper + $minspecial > $length} {
	puts "impossible to generate $length-character password\
		with $minnum numbers, $minlower lowercase letters,\
		$minupper uppercase letters and\
		$minspecial special characters."
	exit 1
}

# if there is any underspecification, use additional lowercase letters
set minlower [expr {$length - ($minnum + $minupper + $minspecial)}]

set lpass ""		;# password chars typed by left hand
set rpass ""		;# password chars typed by right hand

# insert char into password at a random position, thereby spreading
# the different kinds of characters throughout the password
proc insert {pvar char} {
    upvar $pvar p

    set p [linsert $p [rand [expr {(1+[llength $p])}]] $char]
}

proc rand {m} {
    expr {int($m*rand())}
}

# choose left or right starting hand
set initially_left [set isleft [rand 2]]

# given a size, distribute between left and right hands
# taking into account where we left off
proc psplit {max lvar rvar} {
	upvar $lvar left $rvar right
	global isleft

	if {$isleft} {
		set right [expr $max/2]
		set left [expr $max-$right]
		set isleft [expr !($max%2)]
	} else {
		set left [expr $max/2]
		set right [expr $max-$left]
		set isleft [expr $max%2]
	}
}

if {$distribute} {
	set lkeys {q w e r t a s d f g z x c v b}
	set rkeys {y u i o p h j k l n m}
	set lnums {1 2 3 4 5 6}
	set rnums {7 8 9 0}
	set lspec {! @ # \$ %}
	set rspec {^ & * ( ) - = _ + [ ] "{" "}" \\ | ; : ' \" < > , . ? /}
} else {
	set lkeys {a b c d e f g h i j k l m n o p q r s t u v w x y z}
	set rkeys {a b c d e f g h i j k l m n o p q r s t u v w x y z}
	set lnums {0 1 2 3 4 5 6 7 8 9}
	set rnums {0 1 2 3 4 5 6 7 8 9}
	set lspec {! @ # \$ % ~ ^ & * ( ) - = _ + [ ] "{" "}" \\ | ; : ' \" < > , . ? /}
	set rspec {! @ # \$ % ~ ^ & * ( ) - = _ + [ ] "{" "}" \\ | ; : ' \" < > , . ? /}
}

set lkeys_length [llength $lkeys]
set rkeys_length [llength $rkeys]
set lnums_length [llength $lnums]
set rnums_length [llength $rnums]
set ls