File tree 1 file changed +7
-11
lines changed
1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -300,10 +300,7 @@ add_cron_job() {
300
300
local cron_job=" * * * * * /bin/bash $script_path >> $log_dir /$APP_NAME_LOWER -cron.log 2>&1"
301
301
302
302
# Create log directory with error handling
303
- if [ $? -ne 0 ]; then
304
- log " CRITICAL" " Failed to create log directory: $log_dir "
305
- exit 1
306
- fi
303
+ create_dir " $log_dir "
307
304
308
305
309
306
# Temporarily store current crontab to avoid overwriting on error
@@ -314,14 +311,13 @@ add_cron_job() {
314
311
fi
315
312
316
313
# List the current crontab
317
- if ! $crontab_cmd -l > " $temp_cron " 2>&1 ; then
318
- # Handle empty cron file error
314
+ if ! $crontab_cmd -l > " $temp_cron " 2>&1 ; then
315
+ # If no crontab exists, create an empty file
319
316
if grep -q " no crontab for" " $temp_cron " 2> /dev/null; then
320
- grep -v " no crontab for" " $temp_cron " > " ${temp_cron} .clean"
321
- mv " ${temp_cron} .clean" " $temp_cron "
322
- log " No crontab for user $USER_NAME ."
323
- else
324
- log " CRITICAL" " Unable to list current crontab. hello"
317
+ : > " $temp_cron " # Create an empty file
318
+ log " No crontab for user $USER_NAME . Creating new crontab."
319
+ else
320
+ log " CRITICAL" " Unable to list current crontab."
325
321
rm " $temp_cron "
326
322
exit 1
327
323
fi
You can’t perform that action at this time.
0 commit comments