我正在编写自定义计划工具的基础知识,该工具将读取“作业”的配置文件,并将它们添加到计划中以定期运行。它现在是非常基本的,比如重构之前的概念证明和一些其他更高级的功能。
当我尝试运行此程序时,它报告找不到该脚本。脚本“test1.sh”确实存在于我尝试从中运行它的路径中,并且它具有执行权限。
我收到以下错误,但无法解释它或解决它,因为脚本确实存在于我运行它的路径中:
-> ./scheduler-example
2021/08/16 12:48:54 fork/exec /Users/me/scheduler-example/scripts/test1.sh: no such file or directory
调度程序代码:
package main
import (
"io"
"log"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/go-co-op/gocron"
"gopkg.in/yaml.v3"
)
type Config struct {
GlobalLog string `yaml:"GlobalLog"`
Jobs []Job `yaml:"Jobs"`
}
type Job struct {
Name string `yaml:"Name"`
Command string `yaml:"Command"`
Frequency string `yaml:"Frequency"`
Tag string `yaml:"Tag,omitempty"`
Log string `yaml:"Log,omitempty"`
}
const ROOT string = "/Users/me/scheduler-example"
func main() {
// STEP1: Parse the config file
configFile := filepath.Join(ROOT, "config", "scheduler-example.yaml")
f, err := os.Open(configFile)
if err != nil {
log.Fatalln(err)
}
configData, err := io.ReadAll(f)
if err != nil {
log.Fatalln(err)
}
c := Config{}
err = yaml.Unmarshal(configData, &c)
if err != nil {
log.Fatalln(err)
}
// STEP2: Validate the config
if c.GlobalLog == "" {
log.Fatalln("Global log not defined")
}
if c.Jobs == nil {
log.Fatalln("No jobs defined")
}
for _, j := range c.Jobs {
if j.Name == "" {
log.Fatalln("Job name not defined")
}
if j.Command == "" {
log.Fatalln("Job command not defined")
}
if j.Frequency == "" {
log.Fatalln("Job frequency not defined")
}
}
手掌心
慕尼黑5688855
相关分类