X-Git-Url: http://git.sven.stormbind.net/?a=blobdiff_plain;f=home%2Flogin.tcl;fp=home%2Flogin.tcl;h=1d09e7e91c9b3cdf7acb89ed0dc4e5f8fd05897d;hb=5fa67bbfaf6988845526d457d70baf45982b6f48;hp=0000000000000000000000000000000000000000;hpb=1c97c33cfb9f6a5d1fa1892b219c0cb07aa55271;p=sven%2Fscripts.git diff --git a/home/login.tcl b/home/login.tcl new file mode 100644 index 0000000..1d09e7e --- /dev/null +++ b/home/login.tcl @@ -0,0 +1,45 @@ +#!/usr/bin/expect -f + +set pwfile "/etc/openvpn/pass.txt" + +# minimalistic argument parsing, only assumtion is that the first one will be the hostname +if { $argc == 1 } { + set host [lindex $argv 0] + set sshargs "" +} elseif { $argc > 1 } { + set host [lindex $argv 0] + set sshargs [lrange $argv 1 end] +} else { + puts "Error no hostname given" + puts "$argv0 hostname \[other ssh arguments\]" + exit 1 +} + +# extract username and password from an OpenVPN password file +# assumption is that the first line holds the username, the second the password +proc read_pwfile { pwfile } { + global user pass + set pwf [open $pwfile r] + set pwdat [read $pwf] + close $pwf + + set pwlines [split $pwdat "\n"] + set user [lindex $pwlines 0] + set pass [lindex $pwlines 1] +} + + +read_pwfile $pwfile + +# assemble the spawn command we plan to execute +if { [string length $sshargs] == 0 } { + set spawncmd "spawn ssh -l $user $host" +} else { + set spawncmd "spawn ssh -l $user $sshargs $host" +} + +puts "Connecting with user $user to hosts $host with args $sshargs" +eval $spawncmd +expect -re ".*password:" +send "$pass\r" +interact