Skip to content

Instantly share code, notes, and snippets.

@yunginnanet
Last active January 10, 2025 14:43
Show Gist options
  • Save yunginnanet/69124a2f261607d2a144be456b25b0ae to your computer and use it in GitHub Desktop.
Save yunginnanet/69124a2f261607d2a144be456b25b0ae to your computer and use it in GitHub Desktop.
(expect script) mounts a list of sshfs targets, compensates for lack of ssh-agent for batch unlocking of the configured ssh key
#!/usr/bin/expect -f
# mounts a list of sshfs targets
# compensates for lack of ssh-agent for batch unlocking of the configured ssh key
# ----- Config -------------
set src "kayos@fhjones"
set pairs {
"/media/:/home/kayos/fhjones_media/"
"/home/kayos/:/home/kayos/fhjones_home/"
}
# ------------------------
stty -echo
send_user "Enter passphrase: "
expect_user -re "(.*)\n"
set keypassphrase $expect_out(1,string)
stty echo
#debug -now 1
foreach pair $pairs {
set link [split $pair ":"]
set srcdir [lindex $link 0]
set dstdir [lindex $link 1]
# puts "executing: sshfs -o follow_symlinks $src:$srcdir $dstdir"
spawn sshfs -f -o follow_symlinks $src:$srcdir $dstdir
expect_background {
-re "Enter passphrase for key '.*': " {
# puts "sending: $keypassphrase\r"
send -- "$keypassphrase\r"
exp_continue
puts "mounted $srcdir to $dstdir successfully\n"
}
}
}
puts "\n\ndone! sleeping..."
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment