Example #1
0
 /**
  * Run the operation
  */
 public function execute()
 {
     $this->status(Phase::ENVIRONMENT());
     $this->shell_type = $this->shell->getShellType();
     $this->logger->debug("Remote shell is identifying as " . $this->shell_type->value());
     foreach ($this->variables as $key => $value) {
         switch ($this->shell_type) {
             // Bourne-shell compatibles
             default:
                 $cmd = 'export ' . $key . '="' . $value . '"';
                 break;
                 // C-shell compatibles
             // C-shell compatibles
             case ShellType::CSH():
             case ShellType::TCSH():
                 $cmd = 'set ' . $key . '="' . $value . '"';
         }
         $this->output($this->shell->sendSmartCommand($cmd, false));
     }
 }
Example #2
0
 /**
  * @medium
  * @group server
  */
 public function testShellDetection()
 {
     $shell = $this->getShell();
     $type = $shell->getShellType(3);
     $this->assertFalse($type == ShellType::UNKNOWN());
 }
Example #3
0
File: Shell.php Project: bravo3/ssh
 /**
  * Resolve the shell type
  *
  * @param float $timeout
  * @return ShellType
  */
 public function getShellType($timeout = 15.0)
 {
     if ($this->shell_type !== null) {
         return $this->shell_type;
     }
     $this->readyShell($timeout);
     $this->sendln("echo \$0");
     $regex = '/echo \\$0$\\n^(\\-[a-z]+)/sm';
     $out = $this->readUntilExpression($regex, $timeout, true);
     $matches = null;
     preg_match_all($regex, $out, $matches);
     $shell_name = @$matches[1][0];
     // $0 over SSH may prefix with a hyphen
     if ($shell_name[0] == '-') {
         $shell_name = substr($shell_name, 1);
     }
     try {
         $this->shell_type = ShellType::memberByValue($shell_name);
     } catch (UndefinedMemberException $e) {
         $this->shell_type = ShellType::UNKNOWN();
     }
     return $this->shell_type;
 }