home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / examples / heartbeat / hardware-specific / apc-switched-pdu-ssh-monitor.exp < prev    next >
Text File  |  2008-04-24  |  2KB  |  66 lines

  1. #!/usr/bin/expect -f
  2.  
  3. # expect script to login to a baytech management module and control power
  4. # to one of its outlets
  5.  
  6. # gather command line arguments into variables
  7. set host [lrange $argv 0 0]   
  8. set user [lrange $argv 1 1] 
  9. set password [lrange $argv 2 2] 
  10.  
  11. # complain if we don't get exactly 5 arguments
  12. if {$argc!=3} {
  13.     send_user "Usage: apc-switched-pdu-ssh-monitor.exp <host> <user> <password>\n"
  14.     exit 1
  15. }
  16.  
  17. # use a 30 second timeout
  18. set timeout 30 
  19.  
  20. # this disables showing interaction on stdout.  It should be commented
  21. # if you are trying to debug this script and want to see what it is doing
  22. log_user 0
  23.  
  24. # delete old log file and start a new one
  25. #system rm -f /tmp/expect.log
  26. #log_file -a /tmp/expect.log
  27.  
  28. # open ssh connection.  Turn off strict host checking so ssh doesn't ask us 
  29. # if it is ok to connect to this hostname
  30. spawn ssh "-oStrictHostKeyChecking no" $user@$host 
  31.  
  32. # Look for passwod prompt
  33. expect {
  34.     "*?assword:*" {}
  35.     default {
  36.         # password prompt never showed up
  37.         send_user "failed to ssh to host $host\n"
  38.         exit 1
  39.     }
  40. }
  41.  
  42. # Send password aka $password 
  43. send -- "$password\r"
  44. # look for top level prompt
  45. expect {
  46.     "*> *" {}
  47.     default {
  48.         # our user name and password did not work
  49.         send_user "Error: host $host failed to accept username and password\n"
  50.         exit 1
  51.     }
  52. }
  53.  
  54. # send logout command
  55. send -- "4\r"
  56.  
  57. expect {
  58.         eof {}
  59.         default {
  60.                 send_user "Error: could not log out cleanly\n"
  61.                 close
  62.                 wait
  63.                 exit 1
  64.         }
  65. }
  66.