定制 lguichard/process-ssh 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lguichard/process-ssh

最新稳定版本:1.0.4

Composer 安装命令:

composer require lguichard/process-ssh

包简介

Package to use Laravel Process over SSH connections

README 文档

README

Laravel Process over SSH

GitHub Workflow Status (master) Latest Version

Laravel Process over SSH

Laravel Process over SSH is a Laravel package that extends the Illuminate\Process functionality to allow command execution via SSH.

Features

  • Execute shell commands on remote servers using SSH.
  • Full compatibility with Laravel's Process features.
  • Easily configurable options like custom ports, passwords, private keys, and more.

Installation

Install the package via Composer:

composer require lguichard/process-ssh

Usage

To execute a command over SSH, use the Process facade:

Basic Usage

use Illuminate\Support\Facades\Process;

$result = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'password' => 'your_password',
    ])
    ->run('ls -al');

if ($result->successful()) {
    echo $result->output();
} else {
    echo $result->errorOutput();
}

Using Private Key Authentication

$result = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'private_key' => '/path/to/private_key',
    ])
    ->run('ls -al');

Disabling Strict Host Key Checking

$result = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'private_key' => '/path/to/private_key',
    ])
    ->disableStrictHostKeyChecking()
    ->run('ls -al');

Adding Extra SSH Options

$result = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'private_key' => '/path/to/private_key',
    ])
    ->addExtraOption('-o LogLevel=ERROR')
    ->addExtraOption('-o ConnectTimeout=10')
    ->run('ls -al');

Use the favorites method provided by Laravel's Process class.

For more information, refer to the official documentation : https://laravel.com/docs/11.x/processes

$process = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'password' => 'your_password',
    ])
    ->start('bash import.sh');

$result = $process->wait();
[$result1, $result2] = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'password' => 'your_password',
    ])
    ->concurrently(function (Pool $pool) {
        $pool->command('ls -al');
        $pool->command('whoami');
    });
$result = Process::ssh([
        'host' => '192.168.1.10',
        'user' => 'username',
        'password' => 'your_password',
    ])
    ->pool(function (Pool $pool) {
        $pool->command('ls -al');
        $pool->command('whoami');
    });

SSH multiplexing

If you want to execute multiple commands over the same SSH connection, SSH multiplexing allows you to reuse an existing TCP connection, improving efficiency and reducing overhead.

$process = Process::ssh([
    'host' => '192.168.85.5',
    'user' => 'ubuntu',
    'port' => 22,
])->useMultiplexing();

$commands = [
    'ls -al', 'whoami',
    'pwd', 'uname -a',
    'df -h', 'top -bn1',
    'cat /etc/os-release', 'netstat -tuln',
    'uptime', 'tail -n 20 /var/log/syslog',
];

foreach ($commands as $command) {
    $process->run($command)->output();
}

Testing

To run the package's tests:

composer test

Contributing

Contributions are welcome! Please submit a pull request or open an issue on GitHub.

License

This package is open-source software licensed under the MIT license.

For more details, visit the GitHub repository.

Acknowledgments

Special thanks to Spatie's SSH package for inspiring the creation of this package.

Skeleton PHP was created by Nuno Maduro under the MIT license.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-31