File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -300,10 +300,7 @@ add_cron_job() {
300300 local cron_job=" * * * * * /bin/bash $script_path >> $log_dir /$APP_NAME_LOWER -cron.log 2>&1"
301301
302302 # 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 "
307304
308305
309306 # Temporarily store current crontab to avoid overwriting on error
@@ -314,14 +311,13 @@ add_cron_job() {
314311 fi
315312
316313 # 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
319316 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."
325321 rm " $temp_cron "
326322 exit 1
327323 fi
You can’t perform that action at this time.
0 commit comments