summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--monotond.go (renamed from monoton.go)19
1 files changed, 12 insertions, 7 deletions
diff --git a/monoton.go b/monotond.go
index f52c797..d7ebc1e 100644
--- a/monoton.go
+++ b/monotond.go
@@ -12,27 +12,32 @@ import (
func main() {
time_f := flag.String("time", "1m", "Set the time interval.")
cmd_f := flag.String("cmd", "", "Execute the command.")
- vars_f := flag.String("vars", "", "Command line options for the programm.")
+ args_f := flag.String("args", "", "Command line options for the programm.")
flag.Parse()
var (
- time, cmd, vars string
+ time, cmd, args string
)
time = fmt.Sprintf("@every %s", *time_f)
cmd = fmt.Sprintf("%s", *cmd_f)
- vars = fmt.Sprintf("%s", *vars_f)
+ args = fmt.Sprintf("%s", *args_f)
cmd, err := exec.LookPath(cmd)
if err != nil {
- log.Printf("Executable (%s) neither found in PATH variable nor in working directory.\n", *cmd_f)
- os.Exit(1)
+ 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 vars == "" {
+ if args == "" {
c := exec.Command(cmd)
o, err := c.Output()
if err != nil {
@@ -40,7 +45,7 @@ func main() {
}
fmt.Printf("%s", o)
} else {
- c := exec.Command("bash", "-c", cmd+" "+vars)
+ c := exec.Command("bash", "-c", cmd+" "+args)
o, err := c.Output()
if err != nil {
log.Println(err)