summaryrefslogtreecommitdiff
path: root/monotond.go
diff options
context:
space:
mode:
authorhorus_arch2015-03-15 20:51:57 +0100
committerhorus_arch2015-03-15 20:51:57 +0100
commitf964301365c314b388314551f73ea69e9e51df47 (patch)
tree3b9f0fd9ddceac8dae3d261f71a315e10a22c359 /monotond.go
parentfa9dd55107dd08830b2dc5e4cf52674ff19981cf (diff)
downloadmonotond-f964301365c314b388314551f73ea69e9e51df47.tar.gz
Replace -vars flag with -argsHEADmaster
Diffstat (limited to 'monotond.go')
-rw-r--r--monotond.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/monotond.go b/monotond.go
new file mode 100644
index 0000000..d7ebc1e
--- /dev/null
+++ b/monotond.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "github.com/robfig/cron"
+ "log"
+ "os"
+ "os/exec"
+)
+
+func main() {
+ time_f := flag.String("time", "1m", "Set the time interval.")
+ cmd_f := flag.String("cmd", "", "Execute the command.")
+ args_f := flag.String("args", "", "Command line options for the programm.")
+
+ flag.Parse()
+ var (
+ time, cmd, args string
+ )
+
+ time = fmt.Sprintf("@every %s", *time_f)
+ cmd = fmt.Sprintf("%s", *cmd_f)
+ args = fmt.Sprintf("%s", *args_f)
+
+ cmd, err := exec.LookPath(cmd)
+ if err != nil {
+ cmd = fmt.Sprintf("%s", *cmd_f)
+ cmd, err = exec.LookPath("./" + cmd)
+ if err != nil {
+ log.Println(err)
+ log.Printf("Executable (%s) neither found in PATH variable nor in working directory.\n", *cmd_f)
+ os.Exit(1)
+ }
+ }
+
+ job := cron.New()
+ job.AddFunc(time, func() {
+
+ if args == "" {
+ c := exec.Command(cmd)
+ o, err := c.Output()
+ if err != nil {
+ log.Println(err)
+ }
+ fmt.Printf("%s", o)
+ } else {
+ c := exec.Command("bash", "-c", cmd+" "+args)
+ o, err := c.Output()
+ if err != nil {
+ log.Println(err)
+ }
+ fmt.Printf("%s", o)
+ }
+
+ })
+ job.Start()
+
+ for {
+ select {}
+ }
+}