Posted to tcl by rmax at Fri Dec 22 09:17:00 GMT 2017view raw
- #!/usr/bin/tclsh
- # -*- Tcl -*-
- package require Expect
- set prompt ":~> "
- set keyfile "~/.ssh/id_rsa.pub"
- set needcopy 0
- spawn ssh $argv
- expect {
- {[Pp]ass*: } {
- set needcopy 1
- interact "\r" {
- send "\r"
- exp_continue
- }
- }
- $prompt
- }
- if {$needcopy} {
- set fd [open $keyfile]
- gets $fd pubkey
- close $fd
- send " mkdir -p ~/.ssh\r"
- expect $prompt
- send " cat >> ~/.ssh/authorized_keys <<EOF\r$pubkey\rEOF\r"
- expect $prompt
- }
- interact