Fix crontab on systems with crontab
This commit is contained in:
parent
8337b74a80
commit
718220f889
|
@ -1,5 +1,6 @@
|
|||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
@ -28,15 +29,13 @@ def update_crontab_entries(data_path: Path):
|
|||
Update the intake-managed section of the user's crontab.
|
||||
"""
|
||||
# If there is no crontab command available, quit early.
|
||||
cmd = ("command", "-v", "crontab")
|
||||
print("Executing", *cmd, file=sys.stderr)
|
||||
crontab_exists = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
|
||||
if not crontab_exists.stdout:
|
||||
print("Could not update crontab", file=sys.stderr)
|
||||
crontab = shutil.which("crontab")
|
||||
if not crontab:
|
||||
print("No crontab found, skipping", file=sys.stderr)
|
||||
return
|
||||
|
||||
# Get the current crontab
|
||||
cmd = ["crontab", "-e"]
|
||||
cmd = [crontab, "-e"]
|
||||
print("Executing", *cmd, file=sys.stderr)
|
||||
get_crontab = subprocess.run(
|
||||
cmd,
|
||||
|
@ -77,7 +76,7 @@ def update_crontab_entries(data_path: Path):
|
|||
print("Updating", len(new_crontab_lines) - 2, "crontab entries", file=sys.stderr)
|
||||
|
||||
# Save the updated crontab
|
||||
cmd = ["crontab", "-"]
|
||||
cmd = [crontab, "-"]
|
||||
print("Executing", *cmd, file=sys.stderr)
|
||||
new_crontab: bytes = "\n".join(new_crontab_lines).encode("utf8")
|
||||
save_crontab = subprocess.Popen(
|
||||
|
|
Loading…
Reference in New Issue