#! /usr/bin/env expect #+ # NAME: # hammer_sudo.exp # PURPOSE: # "Expect" wrapper for single bash command for passphrase request # CATEGORY: # caida/gen/expect # CALLING SEQUENCE: # hammer_sudo.exp pwd_file cmd # INPUTS: # pwd_file # cmd # RESTRICTIONS: # The location of this script must be in the path # EXAMPLE: # hammer_sudo.exp password.txt IDL_DEV=Z; export IDL_DEV; echo member_domains,/scp | idl -quiet # PROCEDURE: # MODIFICATION HISTORY: # SEP-2009, Paul Hick (UCSD/CAIDA; pphick@caida.org) #- # 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 "sudo -u ark bash -c exit; sudo -u ark $command" match_max 100000 # Look for password prompt expect "*?assword*" # Send password aka $passwd send -- "$passwd\r" # send blank line (\r) to make sure we get back to gui send -- "\r" expect eof