Path: API › 计划任务

`POST /crontab`

创建新的计划任务。

## Request body

_Required._

- `action8.request_time` (string, required) — Unix 时间戳。
- `action8.request_token` (string, required) — 按 API 概览生成的签名。
- `action8.action` (string, required) — 具体操作名称。
  - one of `"AddCrontab"`
- `action8.name` (string, required) — 任务名称
- `action8.type` (string, required) — 周期类型
- `action8.where1` (string, required) — 周期值（天数/分钟数等，取决于 type）
- `action8.sType` (string, required) — 任务类型，见下表
- `action8.sBody` (string, required) — 执行内容
- `action8.sName` (string, optional) — 备注
- `action8.save` (integer, optional) — 备份保留份数
- `action8.backupTo` (string, optional) — 备份目标

## Example request

```text
{
  "request_time": "string",
  "request_token": "string",
  "action": "AddCrontab",
  "name": "string",
  "type": "string",
  "where1": "string",
  "sType": "string",
  "sBody": "string",
  "sName": "string",
  "save": 0,
  "backupTo": "string"
}
```

## Code samples

### cURL（填写面板地址与签名）

```curl
curl --request POST \
  --url "https://your-panel.example.com:8888/crontab" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "request_time=<Unix时间戳>" \
  --data-urlencode "request_token=<按 API 概览生成的签名>" \
  --data-urlencode "action=AddCrontab" \
  --data-urlencode "name=<name>" \
  --data-urlencode "type=<type>" \
  --data-urlencode "where1=<where1>" \
  --data-urlencode "sType=<sType>" \
  --data-urlencode "sBody=<sBody>"
```

## Responses

### default

接口响应，业务状态见下方详细说明。

#### Example

```json
{
  "status": true,
  "msg": "添加成功",
  "id": 6
}
```

- `action8.response.default.status` (boolean, optional) — 请求结果，`true` 表示成功
- `action8.response.default.msg` (string, optional) — 提示信息


## AddCrontab

创建新的计划任务。

- **路由**：`POST /crontab`
- **action**：`AddCrontab`

## 输入参数

| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| action | 是 | String | 固定值 `AddCrontab` |
| name | 是 | String | 任务名称 |
| type | 是 | String | 周期类型 |
| where1 | 是 | String | 周期值（天数/分钟数等，取决于 type） |
| sType | 是 | String | 任务类型，见下表 |
| sBody | 是 | String | 执行内容 |
| sName | 否 | String | 备注 |
| save | 否 | Integer | 备份保留份数 |
| backupTo | 否 | String | 备份目标 |

### sType 任务类型

| 值 | 说明 |
|----|------|
| `toShell` | Shell 脚本 |
| `toUrl` | 访问 URL |
| `toPython` | Python 脚本 |
| `database` | 备份数据库 |
| `site` | 备份网站 |
| `logs` | 日志切割 |
| `rememory` | 释放内存 |

### type 周期类型

| 值 | 说明 | where1 含义 |
|----|------|------------|
| `minute-n` | 每 N 分钟 | 分钟间隔 |
| `hour` | 每小时 | — |
| `day` | 每天 | — |
| `day-n` | 每 N 天 | 天间隔 |
| `week` | 每周 | — |
| `month` | 每月 | — |

## 示例

```
POST /crontab HTTP/1.1
Content-Type: application/x-www-form-urlencoded

action=AddCrontab&name=测试任务&type=minute-n&where1=10&sType=toShell&sBody=echo test&sName=备注&save=0&backupTo=localhost
```

## 输出参数

| 参数名称 | 类型 | 描述 |
|----------|------|------|
| status | Boolean | 请求结果，`true` 表示成功 |
| msg | String | 提示信息 |

```json
{"status": true, "msg": "添加成功", "id": 6}
```

