Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
pvfs2-osd/examples/heartbeat/hardware-specific/apc-switched-pdu-ssh-monitor.exp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65 lines (54 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
# expect script to login to a baytech management module and control power | |
# to one of its outlets | |
# gather command line arguments into variables | |
set host [lrange $argv 0 0] | |
set user [lrange $argv 1 1] | |
set password [lrange $argv 2 2] | |
# complain if we don't get exactly 5 arguments | |
if {$argc!=3} { | |
send_user "Usage: apc-switched-pdu-ssh-monitor.exp <host> <user> <password>\n" | |
exit 1 | |
} | |
# use a 30 second timeout | |
set timeout 30 | |
# this disables showing interaction on stdout. It should be commented | |
# if you are trying to debug this script and want to see what it is doing | |
log_user 0 | |
# delete old log file and start a new one | |
#system rm -f /tmp/expect.log | |
#log_file -a /tmp/expect.log | |
# open ssh connection. Turn off strict host checking so ssh doesn't ask us | |
# if it is ok to connect to this hostname | |
spawn ssh "-oStrictHostKeyChecking no" $user@$host | |
# Look for passwod prompt | |
expect { | |
"*?assword:*" {} | |
default { | |
# password prompt never showed up | |
send_user "failed to ssh to host $host\n" | |
exit 1 | |
} | |
} | |
# Send password aka $password | |
send -- "$password\r" | |
# look for top level prompt | |
expect { | |
"*> *" {} | |
default { | |
# our user name and password did not work | |
send_user "Error: host $host failed to accept username and password\n" | |
exit 1 | |
} | |
} | |
# send logout command | |
send -- "4\r" | |
expect { | |
eof {} | |
default { | |
send_user "Error: could not log out cleanly\n" | |
close | |
wait | |
exit 1 | |
} | |
} |