#! /usr/bin/env expect #+ # NAME: # hammer_ssh.exp # PURPOSE: # "Expect" wrapper for single command for passphrase request # CATEGORY: # caida/gen/expect # CALLING SEQUENCE: # hammer_ssh.exp pwd_file cmd # INPUTS: # pwd_file name of file containing passphrase # cmd command that needs access to remote machines over ssh # PROCEDURE: # The passphrase is used to load all needed keys into ssh-agent. # The agent process is killed upon completion. # The assumption is that public key access is set up with all remote # machines. # MODIFICATION HISTORY: # SEP-2009, Paul Hick (UCSD/CAIDA) # SEP-2010, Paul Hick (UCSD/CAIDA; pphick@caida.org) # First arg is now the name of a file containing the passphrase, # instead of the passphrase itself. #- # set Variables set passwd_file [lrange $argv 0 0] set command [lrange $argv 1 end] set fp [open "$passwd_file" r] set passwd [read $fp] close $fp set timeout -1 #puts "cmd: $command" # now connect to remote UNIX box (ipaddr) with given script to execute spawn bash --login -c "eval `ssh-agent -s`; ssh-add; $command; ssh-agent -k" match_max 100000 # Look for password prompt expect "*?assphrase*" # Send password aka $passwd send -- "$passwd\r" # send blank line (\r) to make sure we get back to gui send -- "\r" expect eof