Created
October 29, 2018 13:24
-
-
Save toddlerya/77844c7e94d15bfeb64e2eaeb658d442 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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