summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf-mode/vyos-update-crontab.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/conf-mode/vyos-update-crontab.py b/src/conf-mode/vyos-update-crontab.py
index d94235f24..ac6ae96d3 100755
--- a/src/conf-mode/vyos-update-crontab.py
+++ b/src/conf-mode/vyos-update-crontab.py
@@ -16,7 +16,7 @@
#
#
-import io
+import os
import re
import sys
@@ -75,7 +75,7 @@ def get_config():
def verify(tasks):
for task in tasks:
if not task["interval"] and not task["spec"]:
- raise VyOSError(task, "Invalid task {0}: must define either interval or crontab-spec".format(task["name"]))
+ raise VyOSError("Invalid task {0}: must define either interval or crontab-spec".format(task["name"]))
if task["interval"]:
if task["spec"]:
@@ -97,10 +97,20 @@ def verify(tasks):
if value > 31:
raise VyOSError("Invalid task {0}: interval in days must not exceed 31".format(task["name"]))
+ if not task["executable"]:
+ raise VyOSError("Invalid task {0}: executable is not defined".format(task["name"]))
+ else:
+ # Check if executable exists and is executable
+ if not (os.path.isfile(task["executable"]) and os.access(task["executable"], os.X_OK)):
+ raise VyOSError("Invalid task {0}: file {1} does not exist or is not executable".format(task["name"], task["executable"]))
+
def generate(tasks):
crontab_header = "### Generated by vyos-update-crontab.py ###\n"
if len(tasks) == 0:
- os.remove(crontab_file)
+ if os.path.exists(crontab_file):
+ os.remove(crontab_file)
+ else:
+ pass
else:
crontab_lines = []
for task in tasks: