commit c26491854d75a9beb1a4618932a8707fd093b1aa
parent 8d112461b1d0be35db557bec64af8a814843a3fa
Author: Alex Balgavy <alexander.balgavy@spaceapplications.com>
Date: Fri, 7 Mar 2025 17:27:02 +0100
sshw: extra options
Diffstat:
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/scripts/sshw b/scripts/sshw
@@ -7,9 +7,22 @@ if { $argc < 1 } {
exit 1
}
+set hosts {
+}
+
set command "ssh"
for {set i 0} {$i < $argc} {incr i} {
switch -glob [lindex $argv $i] {
+ -h {
+ send_user "Targets: [join [dict keys $hosts] ","]\n"
+ exit 0
+ }
+ -M {
+ lappend command "-M"
+ }
+ sftp {
+ lset command 0 sftp
+ }
-J {
lappend command "-J" [lindex $argv [expr {$i + 1}]]
incr i
@@ -18,15 +31,28 @@ for {set i 0} {$i < $argc} {incr i} {
lappend command "-R" [lindex $argv [expr {$i + 1}]]
incr i
}
+ -D {
+ lappend command "-D" [lindex $argv [expr {$i + 1}]]
+ incr i
+ }
-L {
lappend command "-R" [lindex $argv [expr {$i + 1}]]
incr i
}
+ -C {
+ lappend command "-C"
+ }
default {
- lappend command [lindex $argv $i]
+ set host [lindex $argv $i]
+ if {[dict exists $hosts $host]} {
+ set host [dict get $hosts $host]
+ }
+ # TODO: conditionally add -M?
+ lappend command {*}$host
}
}
}
+send_user "Connecting with $command\n"
# Define a subroutine to read password
proc read_password {} {
@@ -81,12 +107,11 @@ proc login {pass command} {
login $pass $command
# Elevate privileges
-send -- "sudo su\n"
-expect -re "password for \[^ \]+: "
-send -- "$pass"
-
-if { $argc == 2 } {
- send -- "[lindex $argv 1]\n"
+if { [lindex $command 0] == "ssh" } {
+ send -- "sudo su\n"
+ expect -re "password for \[^ \]+: "
+ send -- "$pass"
}
+
# Yield control
interact