john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Expect non interactive ssh login improved vm cmd get vm id

!/usr/bin/expect

REMEMBER, the first SSH connection has a yes/no to store the remote certificate

scripting normal interaction: ssh user@address 'df -h' , don't show anything but the output

log_user 0

set timeout 1 set username [lindex $argv 0] set userpass [lindex $argv 1] set remoteaddress 10.10.10.240 set command "df -h"

if { $argc < 2 } { puts "Wrong number of parameters, usage: script username password" exit }

spawn ssh $username@$remoteaddress $command

expect "$username@$remoteaddress's password: "

send "$userpass\n"

interact


!/usr/bin/expect

log_user 0 set timeout 1 set username [lindex $argv 0] set userpass [lindex $argv 1] set remoteaddress 10.10.10.240 set command "vim-cmd vmsvc/getallvms | grep -i 'QA' | cut -f 1 -d ' '"

if { $argc < 2 } { puts "Wrong number of parameters, usage: script username password" exit }

spawn ssh $username@$remoteaddress $command expect "$username@$remoteaddress's password: " send "$userpass\n" interact

set result $expect_out(buffer)

puts $result


  • « Result to variable trim whitespace nested commands instead of pipes
  • Vmware vim cmd command line »

Published

Dec 27, 2011

Category

linux

~132 words

Tags

  • cmd 14
  • expect 7
  • get 22
  • id 1
  • improved 3
  • interactive 4
  • login 11
  • non 5
  • scripts 63
  • ssh 14
  • vm 6