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 / baytech-mgmt-control.exp < prev    next >
Text File  |  2008-04-24  |  3KB  |  120 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. set strip [lrange $argv 3 3]
  11. set outlet [lrange $argv 4 4]
  12. set command [lrange $argv 5 5]
  13.  
  14. # complain if we don't get exactly 5 arguments
  15. if {$argc!=6} {
  16.     send_user "Usage: baytech.exp <host> <user> <password> <strip> <outlet> <cmd>\n"
  17.     send_user "   NOTE: <cmd> may be \"on\" \"off\" or \"reboot\"\n"
  18.     exit 1
  19. }
  20.  
  21. set bay_command ""
  22.  
  23. if { [string compare $command "on"] == 0 } {
  24.     set bay_command "On"
  25. }
  26. if { [string compare $command "off"] == 0 } {
  27.     set bay_command "Off"
  28. }
  29. if { [string compare $command "reboot"] == 0 } {
  30.     set bay_command "Reboot"
  31. }
  32.  
  33. if { [string compare $bay_command ""] == 0 } {
  34.     send_error "Error: <cmd> must be one of on|off|reboot.\n"
  35.     exit 1
  36. }
  37.  
  38. # use a 15 second timeout
  39. set timeout 15
  40.  
  41. # this disables showing interaction on stdout.  It should be commented
  42. # if you are trying to debug this script and want to see what it is doing
  43. log_user 0
  44.  
  45. # delete old log file and start a new one
  46. #system rm -f /tmp/expect.log
  47. #log_file -a /tmp/expect.log
  48.  
  49. # open ssh connection.  Turn off strict host checking so ssh doesn't ask us 
  50. # if it is ok to connect to this hostname
  51. spawn ssh "-oStrictHostKeyChecking no" $user@$host 
  52.  
  53. # Look for passwod prompt
  54. expect {
  55.     "*?assword:*" {}
  56.     default {
  57.         # password prompt never showed up
  58.         send_user "failed to ssh to host $host\n"
  59.         exit 1
  60.     }
  61. }
  62.  
  63. # Send password aka $password 
  64. send -- "$password\r"
  65. # look for top level prompt
  66. expect {
  67.     "*Enter Request*" {}
  68.     default {
  69.         # our user name and password did not work
  70.         send_user "Error: host $host failed to accept username and password\n"
  71.         exit 1
  72.     }
  73. }
  74.  
  75. # send strip name, wait, and then send an extra carriage return
  76. # (for some reason the Baytech will not always continue to the next screen on
  77. # its own)
  78. send -- "$strip\r"
  79. sleep 5
  80. send -- "\r"
  81.  
  82. # wait for prompt for particular strip, then send command to power on 
  83. expect {
  84.     "*RPC-28A>*" {}
  85.     default {
  86.         send_user "Error: failed to select strip $strip\n"
  87.         exit 1
  88.     }
  89. }
  90. send -- "$bay_command $outlet\r"
  91.  
  92. # wait for the Y/N confirmation and send a Y
  93. expect {
  94.     "*Y/N*" {}
  95.     default {
  96.         send_user "Error: failed to issue command for outlet $outlet\n"
  97.         exit 1
  98.     }
  99. }
  100.  
  101. send -- "Y\r"
  102.  
  103. # wait for command to complete 
  104. expect {
  105.     "*RPC-28A>*" {}
  106.     default {
  107.         send_user "Error: failed to confirm command for outlet $outlet\n"
  108.         exit 1
  109.     }
  110. }
  111.  
  112. # Ordinarily we would now send some sort of "logout" command and then expect 
  113. # eof.  For some reason the Baytech devices will not let us logout gracefully 
  114. # however, so we instead just close the connection and return after waiting
  115. # for the result
  116.  
  117. close
  118. wait
  119.  
  120.