/SSHCommand.sh

http://github.com/bububa/MongoHub-Mac · Shell · 45 lines · 19 code · 8 blank · 18 comment · 0 complexity · 6ca79ab06ea112edbee27dd7d963d313 MD5 · raw file

  1. #!/usr/bin/expect -f
  2. #!/bin/sh
  3. # Copyright (C) 2008 Antoine Mercadal
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. set arguments [lindex $argv 0]
  19. set password [lindex $argv 1]
  20. eval spawn $arguments
  21. match_max 100000
  22. set timeout 1
  23. #expect "*yes/no*" {send "yes\r"; exp_continue};
  24. set timeout 30
  25. expect {
  26. "?sh: Error*" {puts "CONNECTION_ERROR"; exit};
  27. "*yes/no*" {send "yes\r"; exp_continue};
  28. "*Could not resolve hostname*" {puts "CONNECTION_REFUSED"; exit};
  29. "*Operation timed out*" {puts "CONNECTION_REFUSED"; exit};
  30. "*Connection refused*" {puts "CONNECTION_REFUSED"; exit};
  31. "*?assword:*" { send "$password\r"; set timeout 4;
  32. expect "*?assword:*" {puts "WRONG_PASSWORD"; exit;}
  33. };
  34. }
  35. puts "CONNECTED";
  36. set timeout -1
  37. expect eof;