title: how to hide ssh expect user/password
body: <p>My Expect script shows password/user in clear text and I want to hide it.</p>
  
  <pre><code>#!/usr/local/bin/expect
  ###########################################################################################    ############
  # Input: It will handle two arguments -&gt; a device and a show command.
  ###########################################################################################    ############
  # ######### Start of Script ######################
  # #### Set up Timeouts - Debugging Variables
  log_user 0
  set timeout 10
  set userid  "USER"
  set password  "PASS"
  # ############## Get two arguments - (1) Device (2) Command to be executed
  set device  [lindex $argv 0] 
  set command [lindex $argv 1]
  spawn /usr/local/bin/ssh -l $userid $device
  match_max [expr 32 * 1024]
  expect {
      -re "RSA key fingerprint" {send "yes\r"}
      timeout {puts "Host is known"}
  }
  expect {
      -re "username: " {send "$userid\r"} 
      -re "(P|p)assword: " {send "$password\r"}
       -re "Warning:" {send "$password\r"}
      -re "Connection refused" {puts "Host error -&gt; $expect_out(buffer)";exit}
      -re "Connection closed"  {puts "Host error -&gt; $expect_out(buffer)";exit}
     -re "no address.*" {puts "Host error -&gt; $expect_out(buffer)";exit}
      timeout {puts "Timeout error. Is device down or unreachable?? ssh_expect";exit}
  }
  expect {
     -re "\[#&gt;]$" {send "term len 0\r"}
     timeout {puts "Error reading prompt -&gt; $expect_out(buffer)";exit}
  }
  expect {
     -re "\[#&gt;]$" {send "$command\r"}
     timeout {puts "Error reading prompt -&gt; $expect_out(buffer)";exit}
  }
  expect -re "\[#&gt;]$"
  set output $expect_out(buffer)
  send "exit\r"
  puts "$output\r\n"
  </code></pre>