Skip to content

Commit f5b46c3

Browse files
authored
Merge pull request #20 from j-arpit/dev
Empty crontab issue resolved
2 parents ce3c728 + 7bcfe3d commit f5b46c3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

setup.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,17 @@ add_cron_job() {
314314
fi
315315

316316
# List the current crontab
317-
if ! $crontab_cmd -l 2>/dev/null > "$temp_cron"; then
318-
log "CRITICAL" "Unable to list current crontab."
319-
rm "$temp_cron"
320-
exit 1
317+
if ! $crontab_cmd -l > "$temp_cron" 2>&1; then
318+
# Handle empty cron file error
319+
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"
325+
rm "$temp_cron"
326+
exit 1
327+
fi
321328
fi
322329

323330
# Ensure the cron job does not already exist

0 commit comments

Comments
 (0)