当前位置: 首页>>代码示例>>PHP>>正文


PHP Net_SSH2::exec方法代码示例

本文整理汇总了PHP中Net_SSH2::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_SSH2::exec方法的具体用法?PHP Net_SSH2::exec怎么用?PHP Net_SSH2::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net_SSH2的用法示例。


在下文中一共展示了Net_SSH2::exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Exec

 public function Exec($command)
 {
     $engine = $this->session->getSpooler();
     if (!isset($engine[0]['shell'])) {
         print "?!";
         exit;
     }
     $shell = $engine[0]['shell'];
     $host = $shell['host'];
     $user = $shell['user'];
     $password = $shell['password'];
     $method = 'CURL';
     set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
     include 'Net/SSH2.php';
     include 'Crypt/RSA.php';
     $ssh = new \Net_SSH2($host);
     if (1) {
         $key = new \Crypt_RSA();
         $ret = $key->loadKey("-----BEGIN RSA PRIVATE KEY-----\nMIICWgIBAAKBgQCzRy01HoHIzBJJb/D8A/eTV3qiZxy0NIR97NE14rJblnJZT5Kg\noP2DvIRzlB0msL5cHQJ/qXYAoemHRDKqNZuj89+MYsBeZqNu3/DXdZLq9XJ8e2rb\nsGrDjHvCHEDWL0JIRFnRacem55+XsUsKTIs4tbcD6adMPIYJSQQ7oB/8AQIBIwKB\ngB67vptkUMNWLwVGY9NuZPSv6SMnnoVK1OJjHIzlCKH8iKGYnMsUSLd/ZynBnpjr\nGVGekrbMl+LZ7YTnHqDV/WxGoWEc3xiHE8/HwZwQZxP92K70inz8+6dGEagsrSqO\nQkdAPR/+qen7uQ9yXqj7WAoNFicPJ2cpo8kuEW33KywzAkEA4yH4jf0uNBFDUkR6\ni9DQC5bsgEloVezWnCsm6eIm5o5SGKPZ6Rpro/h3pq5qvPmCtjrZFnK0Dab9xkFr\n/F9lkwJBAMoQMqxYdnPz74Bto99o0PZrk2ikROwXR9eURi3B4bWGq9+mvN3OEQdE\n8JofGyq60LMlnFAkE7v49fYHziyaFJsCQHTPpGZHsVybKe/LcjlG0WULyhYXH7cp\nWG2SiQqRkFlQgf4LH5xz/Nf8IEcX3x9bv5DrEI8zrQ5V4Zko9bT93HcCQQCEyNDX\np9jP2tCWOWuwEa3jwwkY4PoXfQNTJuxJ9G/AbnDyDnwcup15zje1vKtz2dmaS+pg\njLyC1s2Ea4d8ZUC9AkAeUr/N+011K2zGTjxZnAFY/Ow348bomzddiJYAYA+76exV\n3wUYsjeDxqq8Km93+iMQ8DDNZIvoVcfYQW9BfDlf\n-----END RSA PRIVATE KEY-----   ");
         if (!$ret) {
             echo "loadKey failed\n";
             print "<pre>" . $ssh->getLog() . '</pre>';
             exit;
         }
     } elseif (isset($shell['password'])) {
         $key = $shell['password'];
     } else {
         $key = '';
         // ?! possible ?
     }
     if (!$ssh->login($user, $key)) {
         exit("Login Failed ({$user})");
     }
     return $ssh->exec("system '{$command}'");
 }
开发者ID:AriiPortal,项目名称:I5Bundle,代码行数:35,代码来源:AriiExec.php

示例2: execute

 public function execute($com = false)
 {
     if ($com == false) {
         die("Epic Fail! Yes, it was epic");
     }
     $oldPath = set_include_path("/home/sites/berrics.dev/sharedVendors/phpseclib");
     App::import("Vendor", "SSH2", array("file" => "phpseclib/Net/SSH2.php"));
     set_include_path($oldPath);
     $ssh = new Net_SSH2('10.181.67.27');
     $login = $ssh->login('root', 'WEB1MH0r5t7Wn');
     $out = '';
     switch ($com) {
         case "sync-berrics-all":
             $out .= $ssh->exec("/home/sites/berrics.shell/sync-berrics-all");
             $out .= $ssh->exec("/home/sites/berrics.shell/clear-cache");
             break;
         case "sync-berrics-all-check":
             $out .= $ssh->exec("/home/sites/berrics.shell/sync-berrics-all-check");
             break;
         case "sync-berrics-splash":
             $out .= $ssh->exec("/home/sites/berrics.shell/sync-berrics-splash");
             break;
         default:
             $out .= "Nothing to do...";
             break;
     }
     $this->set(compact("out"));
     //echo $ssh->exec('/home/sites/berrics.shell/sync-berrics-all-check');
 }
开发者ID:josephbergdoll,项目名称:berrics,代码行数:29,代码来源:SystemController.php

示例3: deploy

 public function deploy()
 {
     $releaseId = $this->dataBase->startRelease();
     $ssh = new Net_SSH2(SSH_SERVER);
     $key = new Crypt_RSA();
     $key->setPassword(SSH_PASSWORD);
     $key->loadKey(file_get_contents(PATH_TO_PRIVATE_KEY));
     if (!$ssh->login(SSH_LOGIN, $key)) {
         $this->dataBase->logStep($releaseId, 'ssh ' . SSH_SERVER, ['error' => 'Login failed'], 1);
         exit('Login Failed');
     }
     $ssh->enableQuietMode();
     $command = $this->bash->dtLock('sandbox-mercury', 'mercury');
     $output['success'] = $ssh->exec($command);
     $output['error'] = $ssh->getStdError();
     $this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
     $command = $this->bash->dtPrep('sandbox-mercury', 'mercury', ["mercury" => "dev"]);
     $output['success'] = $ssh->exec($command);
     $output['error'] = $ssh->getStdError();
     $this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
     $command = $this->bash->dtPush('sandbox-mercury', 'mercury');
     $output['success'] = $ssh->exec($command);
     $output['error'] = $ssh->getStdError();
     $this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
 }
开发者ID:Warkot,项目名称:Bolt,代码行数:25,代码来源:Release.class.php

示例4: Exec

    public function Exec($command, $stdin = '')
    {
        $database = $this->session->getDatabase();
        $name = $database['name'];
        $engine = $this->session->getSpoolerByName($name, 'waae');
        if (!isset($engine[0]['shell'])) {
            print "?!";
            exit;
        }
        set_include_path('../vendor/phpseclib' . PATH_SEPARATOR . get_include_path());
        include 'Net/SSH2.php';
        include 'Crypt/RSA.php';
        $shell = $engine[0]['shell'];
        $host = $shell['host'];
        $user = $shell['user'];
        $ssh = new \Net_SSH2($host);
        if (isset($shell['key'])) {
            $key = new \Crypt_RSA();
            $ret = $key->loadKey($shell['key']);
            if (!$ret) {
                echo "loadKey failed\n";
                print "<pre>" . $ssh->getLog() . '</pre>';
                exit;
            }
        } elseif (isset($shell['password'])) {
            $key = $shell['password'];
        } else {
            $key = '';
            // ?! possible ?
        }
        if (!$ssh->login('autosys', $key)) {
            print 'Login Failed';
            print "<pre>" . $ssh->getLog() . '</pre>';
            exit;
        }
        if ($stdin == '') {
            return $ssh->exec(". ~/.bash_profile;{$command}");
        }
        // Test STDIN
        $ssh->enablePTY();
        print "profile" . $ssh->exec(". ~/.bash_profile");
        print "sort" . ($exec = $ssh->exec('sort'));
        $ssh->write(<<<EOF
echo "update_job: SE.ERIC.JOB.JobType_UNIX"
echo "description: 'ok!!'
EOF
);
        $ssh->reset(true);
        $ssh->setTimeout(2);
        print $ssh->read();
        return;
        return $ssh->read();
        // outputs the echo above
    }
开发者ID:AriiPortal,项目名称:ATSBundle,代码行数:54,代码来源:AriiExec.php

示例5: run

 /**
  * @param $command
  *
  * @throws \RuntimeException
  * @throws \Jumper\Exception\CommunicatorException
  * @return String
  */
 public function run($command)
 {
     $result = $this->ssh->exec($command);
     if ($result === false) {
         throw new CommunicatorException($this->ssh->getLastError());
     }
     $error = $this->ssh->getStdError();
     if (!empty($error)) {
         throw new \RuntimeException($error);
     }
     return $result;
 }
开发者ID:sayiho,项目名称:Jumper,代码行数:19,代码来源:Ssh.php

示例6: getPing

function getPing($sourceIP, $destinationIP)
{
    // This will work with any pfSense install. $sourceIP is the IP address of the WAN that you want to
    // use to ping with. This allows you to ping the same address from multiple WANs if you need to.
    global $local_pfsense_ip;
    global $pfSense_username;
    global $pfSense_password;
    $ssh = new Net_SSH2($local_pfsense_ip);
    if (!$ssh->login($pfSense_username, $pfSense_password)) {
        //exit('Login Failed');
        return array(0, 0);
    }
    $terminal_output = $ssh->exec('ping -c 5 -q -S ' . $sourceIP . ' ' . $destinationIP);
    // If using something besides OS X you might want to customize the following variables for proper output of average ping.
    $findme_start = '= ';
    $start = strpos($terminal_output, $findme_start);
    $ping_return_value_str = substr($terminal_output, $start + 2, 100);
    $findme_stop1 = '.';
    $stop = strpos($ping_return_value_str, $findme_stop1);
    $findme_avgPing_decimal = '.';
    $avgPing_decimal = strpos($ping_return_value_str, $findme_avgPing_decimal, 6);
    $findme_forward_slash = '/';
    $avgPing_forward_slash = strpos($ping_return_value_str, $findme_forward_slash);
    $avgPing = substr($ping_return_value_str, $stop + 5, $avgPing_decimal - $avgPing_forward_slash - 1);
    return $avgPing;
}
开发者ID:maaximal,项目名称:Network-Status-Page,代码行数:26,代码来源:SABthrottle.php

示例7: Exec

 public function Exec($host, $user, $password, $command)
 {
     $ssh = new Net_SSH2($host);
     if (!$ssh->login($user, $password)) {
         exit('Login Failed');
     }
     echo $ssh->exec("system '{$command}'");
 }
开发者ID:AxelANGENAULT,项目名称:CoreBundle,代码行数:8,代码来源:AriiSSH.php

示例8: ConectSSHStation

function ConectSSHStation($server)
{
    $ssh = new Net_SSH2($server);
    if (!$ssh->login(userubnt, passubnt)) {
        print "Login Failed {$server}";
    }
    $mca = $ssh->exec("mca-status");
    return $mca;
}
开发者ID:procamora,项目名称:Scripts-PHP,代码行数:9,代码来源:MonitorizaAntenas.php

示例9: exit

 function delete_user($username, $server_host, $server_username, $server_password)
 {
     $ssh = new Net_SSH2($server_host);
     if ($ssh->login($server_username, $server_password) == false) {
         exit('Login Failed');
     }
     $command = 'userdel -r ' . $username;
     echo $ssh->exec($command);
 }
开发者ID:istrwei,项目名称:vpn_manager,代码行数:9,代码来源:lib.php

示例10: Exec

 public function Exec($command)
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
     include 'Net/SSH2.php';
     $ssh = new \Net_SSH2($this->host);
     if (!$ssh->login($this->user, $this->password)) {
         exit('Login Failed');
     }
     return $ssh->exec("system '{$command}'");
 }
开发者ID:AriiPortal,项目名称:Arii,代码行数:10,代码来源:AriiExec.php

示例11: runcmd

function runcmd($cmd)
{
    include 'Net/SSH2.php';
    $ssh = new Net_SSH2('localhost');
    if (!$ssh->login('rc', 'cacapedo')) {
        exit('Login Failed');
    }
    // echo $ssh->exec('pwd');
    $r = $ssh->exec($cmd);
    return str_replace("\n", "<br>", $r);
}
开发者ID:raulastu,项目名称:sshmail,代码行数:11,代码来源:runbash.php

示例12: set_addr

function set_addr($subnet, $interface)
{
    $interface = $interface != '' ? $interface : $GLOBALS['ethernet_forenaming_scheme'] . '1';
    $ip = explode('/', $subnet);
    $cidr = $ip[1];
    $ip_parts = explode('.', $ip[0]);
    $ip_parts[3] = $ip_parts[3] + 1;
    $gw = implode('.', $ip_parts);
    $ip_parts[3] = $ip_parts[3] + 1;
    $ip = implode('.', $ip_parts);
    $ssh = new Net_SSH2('192.168.88.1');
    if ($ssh->login('admin', $GLOBALS['admin_password'])) {
        //while we're here we might as well reset the mac addresses again.
        $detail = $ssh->exec('int eth print');
        if (preg_match_all("/{$GLOBALS['ethernet_forenaming_scheme']}/", $detail, $matches)) {
            $i = 1;
            foreach ($matches[0] as $match) {
                $ssh->exec('int ethernet reset-mac-address ' . $GLOBALS['ethernet_forenaming_scheme'] . $i);
                $ssh->exec(':beep frequency=120 length=2ms;');
                $i++;
                if ($i == '10') {
                    $ssh->exec('int ethernet reset-mac-address ' . $GLOBALS['sfp_forenaming_scheme'] . '1');
                }
            }
        }
        $ssh->exec('ip address add address=' . $ip . '/' . $cidr . ' interface=' . $interface);
        //set the ip on the specified interface.
        $ssh->exec('ip route add dst-address=0.0.0.0/0 gateway=' . $gw);
        //add the default route
    }
}
开发者ID:jamenlang,项目名称:mikrotik-php,代码行数:31,代码来源:fast_config.php

示例13: getInfo

function getInfo($ip, $sshkey_location)
{
    $ssh = new Net_SSH2($ip);
    //key
    $key = new Crypt_RSA();
    $key->loadKey(file_get_contents($sshkey_location));
    if (!$ssh->login('root', $key)) {
        die("SSH Login Failed!");
    } else {
        $return['disk_usage'] = $ssh->exec("df -k .|awk 'NR==2 {print \$5}'");
        $return['disk_remaining'] = 100 - substr($return['disk_usage'], 0, -1) . "%";
        $uptime = $ssh->exec('echo `uptime`');
        list($uptime, $load) = explode('load average:', $uptime);
        list($trash, $uptime) = explode(' up ', $uptime);
        list($uptime, $trash) = explode(', ', $uptime);
        $return['uptime'] = $uptime;
        $return['load'] = $load;
        //get memory
        $return['memory_free'] = $ssh->exec("cat /proc/meminfo|grep 'MemFree'");
        list($trash, $return['memory_free']) = explode('MemFree:', $return['memory_free']);
    }
    return $return;
}
开发者ID:newmight2015,项目名称:p2pmine-manager,代码行数:23,代码来源:.functions.php

示例14: runCommand

 public function runCommand($cmd)
 {
     if (!empty($this->key_path)) {
         $key = new Crypt_RSA();
         $key->loadKey(file_get_contents($this->key_path));
     }
     $ssh = new Net_SSH2($this->host, $this->port);
     if ($key) {
         $ssh->login($this->user, $key);
     } else {
         $ssh->login($this->user, $this->password);
     }
     $out = $ssh->exec($cmd);
     return $out;
 }
开发者ID:rafeco,项目名称:simpledeployer,代码行数:15,代码来源:SshHelper.php

示例15: doRunTests

 private function doRunTests($testSuite, array $arguments)
 {
     $arguments = implode(' ', $arguments);
     $this->ssh->exec("ps -ef | grep \"php console tests:run\" | grep -v grep | awk '{print \$2}' | xargs kill -9");
     if ('all' === $testSuite) {
         $this->ssh->exec('php console tests:run --options="--colors" ' . $arguments);
     } elseif ('ui' === $testSuite) {
         $this->ssh->exec('php console tests:run-ui --persist-fixture-data --assume-artifacts ' . $arguments);
     } else {
         $this->ssh->exec('php console tests:run --options="--colors" --testsuite="unit" ' . $arguments);
         $this->ssh->exec('php console tests:run --options="--colors" --testsuite="' . $testSuite . '" ' . $arguments);
     }
     if ('system' === $testSuite) {
         $this->ssh->exec("tar -cjf tests/PHPUnit/System/processed/processed.tar.bz2 tests/PHPUnit/System/processed/ plugins/*/tests/System/processed/ --exclude='.gitkeep' --exclude='tests/PHPUnit/System/processed/processed.tar.bz2'");
     }
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:16,代码来源:Remote.php


注:本文中的Net_SSH2::exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。