1.0.5 • Published 6 years ago

ssh2-auto v1.0.5

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

ssh2-auto: 在远程服务器上执行程序

通过ssh,执行远程服务器上的程序。 在ssh2-robot的基础上添加本地命令的执行,op: 'local',或者op: 'spawn'.

Installation

npm install ssh2-auto

Usage

var schedule = require('ssh2-auto');

function remoteTask(){
    schedule({
        host: '***',
        port: '22',
        username: '***',
        password: '***'
    },{
        ready: {
            op: 'exec',
            cmd: 'ls -l > out.txt',
            cb: function(code, stdout, stderr, signal) {
                console.log('ls', code);
                process.stdout.write(stdout);
                process.stderr.write(stderr);
                return 'fastGet';
            }
        },
        'fastGet': {
            op: 'get',
            remote: '/root/out.txt',
            local: '/mac/out.txt', 
            cb: function(err) {
                console.log(remoteFilePath + '    ===>    ' + localFilePath);
                err && console.log(err);
                return 'fastPut';
            }
        },
        'fastPut': {
            op: 'put',
            remote: '/root/out.txt.bak',
            local: '/mac/out.txt.bak', 
            cb: function(err) {
                console.log(localFilePath + '    ===>    ' + remoteFilePath);
                err && console.log(err);
                return 'end';
            }
        }
    });
}
function localTask(){
    schedule({}, {
        'ready': {
            op: 'local',
            cmd: 'pwd',
            cb: function(code, stdout, stderr, signal) {
                console.log('pwd', code);
                process.stdout.write(stdout);
                process.stderr.write(stderr);
                return 'node';
            }
        },
        'node': {
            op: 'local',
            cmd: 'node test.js',
            cb: function(code, stdout, stderr, signal) {
                console.log('node test.js', code);
                process.stdout.write(stdout);
                process.stderr.write(stderr);
                return 'next';
            }
        },
        'next': {
            op: 'spawn',
            cmd: ['test.js','args'],
            cb: function(code, stdout, stderr, signal) {
                console.log('node test.js args', code);
                process.stdout.write(stdout);
                process.stderr.write(stderr);
                return 'end';
            }
        }
    });
}
remoteTask();
localTask();

Dependences

ssh2
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago