summaryrefslogtreecommitdiff
path: root/src/conf-mode/vyos-update-crontab.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-09-08 04:40:33 +0200
committerDaniil Baturin <daniil@baturin.org>2017-09-08 04:40:33 +0200
commit8a4aeb2df4f7f1c217834865ca297495057a82bc (patch)
tree4acbbd9dacaae4b26624080bb6678b640bc798b0 /src/conf-mode/vyos-update-crontab.py
parentb8ef3cc7d3dd69eae3b93a581b07954df0694479 (diff)
downloadvyos-1x-8a4aeb2df4f7f1c217834865ca297495057a82bc.tar.gz
vyos-1x-8a4aeb2df4f7f1c217834865ca297495057a82bc.zip
Better checks in the cron script.
Check if crontab exists before trying to delete it. Fail commit if executable is not defined in the task.
Diffstat (limited to 'src/conf-mode/vyos-update-crontab.py')
-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: