Go Command Agent

很多时候大家需要去某个服务器上去执行一段命令或者上传/下载一个文件,这个命令还可能是时间比较久的,不想一直等在那里,特别是内网里面,不要复杂的认证,比如CICD里面,这时候大家可以使用这个command agent部署在server上,从而通过rest api来轻松的执行命令。

github:GodQ/go-rest-agent (github.com)

这个agent是使用Go编写的,提供了多种OS/CPU的版本,可以拿来即用。

部署命令:

nohup ./agent_linux_amd64 5000 &

下面是这个agent的5个api:

Agent API Example

Post File

复制代码
curl -L -XPOST '127.0.0.1:5000/api/v1/file' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-F 'target_path="/tmp/aaa.yaml"' \
-F 'file=@"/Users/GodQ/a.yaml"'

response:

复制代码
{
    "message": "Upload file successfully"
}

Get File

复制代码
curl -L '127.0.0.1:5000/api/v1/file?file_path=%2Ftmp%2Faaa.yaml' \
-H 'Content-Type: application/x-www-form-urlencoded'

response:

复制代码
<file content>

Post Command Request Task

复制代码
curl -L -XPOST '127.0.0.1:5000/api/v1/tasks' \
-H 'Content-Type: application/json' \
-d '{
    "command": "date; sleep 5; date",
    "timeout_seconds": 6
}'

response:

复制代码
{
    "task_id": 1,
    "command": "date; sleep 5; date",
    "timeout_seconds": 6,
    "retry_count": 0,
    "extra": "",
    "key": "",
    "callback_url": "",
    "status": "doing",
    "return_code": 0,
    "error_msg": "",
    "start_time": "0001-01-01T00:00:00Z",
    "end_time": "0001-01-01T00:00:00Z",
    "duration": 0,
    "log_redis_key": "",
    "log_redis_url": "",
    "thread_name": "",
    "stdout": ""
}

List Tasks

复制代码
curl -L '127.0.0.1:5000/api/v1/tasks'

response:

复制代码
{
    "1": {
        "task_id": 1,
        "command": "date; sleep 5; date",
        "timeout_seconds": 6,
        "retry_count": 0,
        "extra": "",
        "key": "",
        "callback_url": "",
        "status": "done",
        "return_code": 0,
        "error_msg": "",
        "start_time": "2023-11-13T11:06:50.863401+08:00",
        "end_time": "2023-11-13T11:06:55.971313+08:00",
        "duration": 5,
        "log_redis_key": "",
        "log_redis_url": "",
        "thread_name": "",
        "stdout": "Mon Nov 13 11:06:50 CST 2023\nMon Nov 13 11:06:55 CST 2023\n"
    }
}

Get Task by ID

复制代码
curl -L '127.0.0.1:5000/api/v1/tasks?task_id=1'

response:

复制代码
{
    "1": {
        "task_id": 1,
        "command": "date; sleep 5; date",
        "timeout_seconds": 6,
        "retry_count": 0,
        "extra": "",
        "key": "",
        "callback_url": "",
        "status": "done",
        "return_code": 0,
        "error_msg": "",
        "start_time": "2023-11-13T11:06:50.863401+08:00",
        "end_time": "2023-11-13T11:06:55.971313+08:00",
        "duration": 5,
        "log_redis_key": "",
        "log_redis_url": "",
        "thread_name": "",
        "stdout": "Mon Nov 13 11:06:50 CST 2023\nMon Nov 13 11:06:55 CST 2023\n"
    }
}
相关推荐
Charary23 分钟前
字符设备驱动开发与杂项开发
linux·驱动开发
孤寂大仙v1 小时前
【Linux笔记】理解文件系统(上)
linux·运维·笔记
钢板兽2 小时前
Java后端高频面经——JVM、Linux、Git、Docker
java·linux·jvm·git·后端·docker·面试
byxdaz2 小时前
NVIDIA显卡驱动、CUDA、cuDNN 和 TensorRT 版本匹配指南
linux·人工智能·深度学习
大白的编程日记.3 小时前
【Linux学习笔记】Linux基本指令分析和权限的概念
linux·笔记·学习
努力学习的小廉3 小时前
深入了解Linux —— 调试程序
linux·运维·服务器
螺旋式上升abc3 小时前
GO语言学习笔记
笔记·学习·golang
努力学习的小廉3 小时前
深入了解Linux —— git三板斧
linux·运维·git
只做开心事3 小时前
Linux网络之数据链路层协议
linux·服务器·网络
钡铼技术物联网关4 小时前
ARM嵌入式低功耗高安全:工业瘦客户机的智慧城市解决方案
linux·安全·智慧城市