Files
iAs/resources/skills/manage_scheduled_task/scripts/manage.sh
T
wunianxiao 81c736f873 refactor: skill 脚本输出改为结构化 JSON
- query_weather: {location, now: {temp,text}, forecast: [{date,day,night,tempMin,tempMax}]}
- search_web: {query, answer, results: [{title,url,content}]}
- get_current_datetime: {datetime}
- list_scheduled_tasks: {tasks: [{name,description,enabled,command,...}]}
- manage_scheduled_task: {ok, action, name} / {error}

LLM 直接看到结构化数据,不再依赖脚本拼接的中文自然语言
2026-06-02 10:32:27 +08:00

40 lines
2.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 管理定时任务 → JSON 输出
read -r input
ACTION=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('action',''))" 2>/dev/null)
NAME=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('name',''))" 2>/dev/null)
CMD=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('command',''))" 2>/dev/null)
INTERVAL=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('interval_seconds',3600))" 2>/dev/null)
DESC=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('description',''))" 2>/dev/null)
DB_URL="${DATABASE_URL}"
[ -z "$DB_URL" ] && echo '{"error":"数据库未配置"}' && exit 0
[ -z "$NAME" ] && echo '{"error":"请提供 name 参数"}' && exit 0
case "$ACTION" in
add)
[ -z "$CMD" ] && echo '{"error":"add 需要 command 参数"}' && exit 0
psql "$DB_URL" -c "
INSERT INTO scheduled_tasks (id, name, description, command, interval_seconds, enabled, next_run_at)
VALUES (gen_random_uuid(), '$NAME', '$DESC', '$CMD', $INTERVAL, true, NOW() + interval '$INTERVAL seconds')
ON CONFLICT (name) DO UPDATE SET command=EXCLUDED.command, interval_seconds=EXCLUDED.interval_seconds, enabled=true, description=EXCLUDED.description
" 2>/dev/null && echo '{"ok":true,"action":"add","name":"'"$NAME"'"}' || echo '{"error":"添加失败"}'
;;
delete)
psql "$DB_URL" -c "DELETE FROM scheduled_tasks WHERE name = '$NAME'" 2>/dev/null
echo '{"ok":true,"action":"delete","name":"'"$NAME"'"}'
;;
enable)
psql "$DB_URL" -c "UPDATE scheduled_tasks SET enabled = true WHERE name = '$NAME'" 2>/dev/null
echo '{"ok":true,"action":"enable","name":"'"$NAME"'"}'
;;
disable)
psql "$DB_URL" -c "UPDATE scheduled_tasks SET enabled = false WHERE name = '$NAME'" 2>/dev/null
echo '{"ok":true,"action":"disable","name":"'"$NAME"'"}'
;;
*)
echo '{"error":"未知操作: '"$ACTION"'(支持: add, delete, enable, disable"}'
exit 1
;;
esac