-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backup and restore crontab file #263
base: main
Are you sure you want to change the base?
Conversation
Is it possible to do this with a crontab library? Seems dirty to write this feature in bash when it may not be necessary. |
I don't know about any simple libraries that just read and write to the system crontab. Imo the backing up part would be overkill with a library. |
Just looked and agree that there isn't a good library for this. |
escape any present " characters in the crontab line
Let's add some tests for this and then I'm good merging it in. |
for x in f: | ||
# the replace sanitizes the crontab line of any present " characters. | ||
sanitized = x.replace('"', '\\"') | ||
cmd = f"(crontab -l ; echo \"{sanitized}\") | sort - | uniq - | crontab -" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not convinced this is the best way to do this. This escaping may not work properly in all cases. Make sure to test it with some complex commands that require proper escaping.
Also maybe use shlex.quote()
? https://docs.python.org/3.5/library/shlex.html#shlex.quote
simple solution for backing up and restoring the crontab. #215