From 346a5305137bc524f175a4d1be716167227fc41e Mon Sep 17 00:00:00 2001 From: AlexisHenry Date: Mon, 23 Jan 2023 09:42:40 +0100 Subject: [PATCH 1/3] feat(cron): configure save cron --- utils/cron.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 utils/cron.sh diff --git a/utils/cron.sh b/utils/cron.sh new file mode 100644 index 0000000..4d4460f --- /dev/null +++ b/utils/cron.sh @@ -0,0 +1,24 @@ +# This script is made to set a cron task used to save your shared files +# To configure the cron, change the variable below: + +source utils/tools.sh; + +# Duration between running crons +duration="5 10 * * *"; + +# Path to shared folder +shared="/var/www/cdn.alexishenry.eu/public/shared"; + +# Save folder path +saved="/home/alexis/save_my_files"; + +function crontab() { + if [[ ! -d ${saved} ]]; then + throw "Save folder specified [ ${saved} ] does not exist" true; + elif [ "$EUID" -ne 0 ]; then + throw "Please, run this script as root" true; + fi + echo "${duration} cp -r ${shared} ${saved}/cdn_save_$(date +%s)" > /etc/cron.hourly/cdn-autosave +} + +crontab; \ No newline at end of file From 16764f063a50bf40a47930200731d011a720163a Mon Sep 17 00:00:00 2001 From: AlexisHenry Date: Mon, 23 Jan 2023 09:49:18 +0100 Subject: [PATCH 2/3] fix(cron): generate timestamp in crontab --- utils/cron.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cron.sh b/utils/cron.sh index 4d4460f..2625161 100644 --- a/utils/cron.sh +++ b/utils/cron.sh @@ -18,7 +18,7 @@ function crontab() { elif [ "$EUID" -ne 0 ]; then throw "Please, run this script as root" true; fi - echo "${duration} cp -r ${shared} ${saved}/cdn_save_$(date +%s)" > /etc/cron.hourly/cdn-autosave + echo "${duration} cp -r ${shared} ${saved}/cdn_save_\$(date +%s)" > /etc/cron.hourly/cdn-autosave } crontab; \ No newline at end of file From 744fec86414c8a9489873cf3189f79052182a8dc Mon Sep 17 00:00:00 2001 From: AlexisHenry Date: Mon, 23 Jan 2023 09:50:48 +0100 Subject: [PATCH 3/3] fix(cron): remove duration --- utils/cron.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/utils/cron.sh b/utils/cron.sh index 2625161..ae110b6 100644 --- a/utils/cron.sh +++ b/utils/cron.sh @@ -3,9 +3,6 @@ source utils/tools.sh; -# Duration between running crons -duration="5 10 * * *"; - # Path to shared folder shared="/var/www/cdn.alexishenry.eu/public/shared"; @@ -18,7 +15,7 @@ function crontab() { elif [ "$EUID" -ne 0 ]; then throw "Please, run this script as root" true; fi - echo "${duration} cp -r ${shared} ${saved}/cdn_save_\$(date +%s)" > /etc/cron.hourly/cdn-autosave + echo "cp -r ${shared} ${saved}/cdn_save_\$(date +%s)" > /etc/cron.hourly/cdn-autosave } crontab; \ No newline at end of file