예제 #1
0
 /**
  * Send a command, logging error output to the filesystem
  *
  * The output of the commands will be send to the logger.
  *
  * @param string   $cmd
  * @param int      $timeout
  * @param string[] $allowed_errors Convert these errors to notices
  * @return bool True if the command completes without error
  */
 protected function sendCommand($cmd, $timeout = 15, array $allowed_errors = [])
 {
     $this->logger->debug("Execute: " . $cmd);
     $log_file = $this->log_prefix . '-' . self::$log_index++ . '.error.log';
     $output = $this->shell->sendSmartCommand($cmd . ' 2> ' . $log_file, false, $timeout, true);
     $errors = trim($this->shell->sendSmartCommand('cat ' . $log_file, true, 3, true));
     $this->output($output);
     if ($errors) {
         $false_positive = false;
         foreach ($allowed_errors as $allowed_error) {
             if (substr($errors, 0, strlen($allowed_error)) == $allowed_error) {
                 $false_positive = true;
                 break;
             }
         }
         if ($false_positive) {
             // Acceptable errors
             $this->logger->notice($errors);
             return true;
         } else {
             // Unacceptable errors
             $this->logger->debug("Command returned errors:");
             $this->error($errors);
             return false;
         }
     } else {
         // No errors
         return true;
     }
 }
예제 #2
0
 /**
  * Send and log a smart command
  *
  * @param string $cmd
  * @param int    $timeout
  */
 public function sendCommand($cmd, $timeout = 15)
 {
     if (substr($this->output, -1) !== "\n") {
         $this->addLog("\n");
     }
     $this->addLog($this->getPrompt() . $cmd . "\n");
     $this->addLog($this->shell->sendSmartCommand($cmd, true, $timeout, true));
 }
예제 #3
0
 /**
  * Zero out a remote file and then delete it
  *
  * @param string $fn
  */
 protected function secureDeleteFile($fn)
 {
     $this->shell->sendSmartCommand('dd if=/dev/zero of="' . $fn . '" count=1 bs=`wc -c < "' . $fn . '"`', true, self::CMD_TIMEOUT, true);
     $this->shell->sendSmartCommand('rm -f "' . $fn . '"', true, self::CMD_TIMEOUT, true);
 }