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"
    }
}
相关推荐
南种北李2 分钟前
Linux自动化构建工具Make/Makefile
linux·运维·自动化
小飞猪Jay7 分钟前
面试速通宝典——10
linux·服务器·c++·面试
暗恋 懒羊羊44 分钟前
Linux 生产者消费者模型
linux·开发语言·ubuntu
吃着火锅x唱着歌2 小时前
Redis设计与实现 学习笔记 第五章 跳跃表
golang
安红豆.2 小时前
Linux基础入门 --13 DAY(SHELL脚本编程基础)
linux·运维·操作系统
..空空的人2 小时前
linux基础指令的认识
linux·运维·服务器
penny_tcf2 小时前
Linux基础命令halt详解
linux·运维·服务器
荣世蓥2 小时前
10.2 Linux_进程_进程相关函数
linux·运维·服务器
安全不再安全4 小时前
Linux 安装 yum
linux·运维·centos
水饺编程4 小时前
【英特尔IA-32架构软件开发者开发手册第3卷:系统编程指南】2001年版翻译,1-2
linux·嵌入式硬件·fpga开发