Skip to content

Instantly share code, notes, and snippets.

@toddlerya
Created October 29, 2018 13:24
Show Gist options
  • Save toddlerya/77844c7e94d15bfeb64e2eaeb658d442 to your computer and use it in GitHub Desktop.
Save toddlerya/77844c7e94d15bfeb64e2eaeb658d442 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os/exec"
"github.com/robfig/cron"
)
func execShellNoResult(command string) {
cmd := exec.Command("/bin/bash", "-c", command)
err := cmd.Start()
if err != nil {
fmt.Printf("exec command:%v error:%v\n", command, err)
}
fmt.Printf("Waiting for command:%v to finish...\n", command)
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v\n", err)
}
return
}
func cronJob() {
c := cron.New()
spec := "20 18 * * * *"
c.AddFunc(spec, func() {
execShellNoResult("sh /root/super_seat.sh")
})
c.Start()
select {} //阻塞主线程不退出
}
func main() {
cronJob()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment