--- /dev/null
+#!/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