Coder Social home page Coder Social logo

154650362 / shell-agent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firnsan/shell-agent

0.0 1.0 0.0 925 KB

Agent program installed on remote host, help you to execute shell command on the remote host via HTTP. Also help to transport file to/from remote host.

Go 100.00%

shell-agent's Introduction

Shell Agent

Shell Agent, is a program installed on remote host, help you to execute shell command on the remote host.

This agent can also help to transport file to/from remote host.

Install

go build
./shell_agent 

Now you can visit the agent via 8080 port.

The usage is simple:

Shell Agent.

        Usage:
        shell_agent [--cnf=<path>] [--addr=<addr>]
        shell_agent -h | --help
        shell_agent --version

        Options:
        --cnf=<path>  config file path [default: ].
        --addr=<addr>  config file path [default: :8080].

Execute command

There are two ways to execute command on remote host: sync(is default) and async.

sync

Type the following curl request will hang and wait for sleep 5 to finish.

curl -d '{"cmd":"sleep 5 && echo test sleep"}' http://127.0.0.1:8080/api/v1/cmd/run
{"errno":0,"error":"succeed","data":{"id":"bda8616a-0179-4c54-468b-918e15112006","status":"finished","error":"","cmd":"sleep 600 \u0026\u0026 echo test sleep","env":null,"stdout":"test sleep\n","stderr":"","exit_code":0,"pid":10266,"create_time":"2018-02-25T19:01:32.870915989+08:00","finish_time":"2018-02-25T19:11:32.875958476+08:00"}}

Take a careful look at the response:

{
    "errno": 0, 
    "error": "succeed", 
    "data": {
        "id": "bda8616a-0179-4c54-468b-918e15112006", 
        "status": "finished", 
        "error": "", 
        "cmd": "sleep 600 && echo test sleep", 
        "env": null, 
        "stdout": "test sleep\n", 
        "stderr": "", 
        "exit_code": 0, 
        "pid": 10266, 
        "create_time": "2018-02-25T19:01:32.870915989+08:00", 
        "finish_time": "2018-02-25T19:11:32.875958476+08:00"
    }
}

The returned http response contain:

  • id: UUID of the job .
  • status: Status of the job, maybe running, finished(the command exited with zero exit code), failed(the command failed to start, or be killed, or exited with non-zero exit code), canceled(canceled by user)
  • error: The reason why the job failed.
  • stdout: Stdout of the command.
  • stderr: Stderr of the command.
  • exit_code: Exit code of the command.

async

Type the following curl request will not hang and return immediately. The returned http response only contain the job id, which can be use to query job progress.

curl -d '{"cmd":"sleep 600 && echo test sleep", "async":true}' http://127.0.0.1:8080/api/v1/cmd/run  
{"errno":0,"error":"succeed","data":{"id":"3dcb8bb9-5aab-4a5c-7575-fa11294d2dff","create_time":"2018-02-25T19:38:38.539287299+08:00"}}

The returned http response contain:

  • id: UUID of the job .

Query a job

You can use the job id to query the job info:

curl http://127.0.0.1:8080/api/v1/cmd/query?id=3dcb8bb9-5aab-4a5c-7575-fa11294d2dff

Cancel a job

You can cancel a runnning job:

curl http://127.0.0.1:8080/api/v1/cmd/cancel?id=3dcb8bb9-5aab-4a5c-7575-fa11294d2dff

List all command jobs

You can get all jobs ordered by create time desc:

curl http://127.0.0.1:8080/api/v1/cmd/list

shell-agent's People

Contributors

firnsan avatar flike avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.