Crontab runs more than once? Or something.. [SOLVED]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
CommonGrackle
Level 1
Level 1
Posts: 25
Joined: Sat Dec 08, 2018 6:55 pm

Crontab runs more than once? Or something.. [SOLVED]

Post by CommonGrackle »

So I have a crontab set up on each of my machines that basically checks to see if it's a certain day of the week, and if it's that day of the week (e.g., Friday) runs a very basic bash script that puts a tiny (< 30kb) text-file reminder flag ("this-machine-needs-backup.flag") on the desktop.

I have other scripts that I run when I get around to it, that take care of the tasks I'm reminded of via the flag. For example, I have a script file that runs system maintenance tasks (system-maint.sh). One of the first things those script files do is rm that flag, so I know I've taken care of it for the week/month/whatever.

All working well, except in this circumstance:

1. Crontab set to run at 8pm every day.
2. Crontab runs, and sets the reminder flag if it's appropriate to that machine.
3. When I later run the associated maintenance script, though, two things can happen:

If I run the maintenance script, say, next day, no problem. Script removes flag and runs tasks.

However, if I run the maintenance script, say, at 8:50pm -- which is looooonnggg after that little task of checking the dow and then creating a tiny text file on the desktop --- the maintenance script removes the flag, and completes the tasks... but then the flag text file just reappears back on the desktop a few minutes later.

If I remove the flag text file by hand during same time frame, it still comes back.

What is happening that's recreating that text file or continuing to run the crontab tasks or...? Is there a time range, for example, that crontab continues to run within, even when I've given it a specific time to run.

Here's my crontab setup:

Code: Select all

# m  h   dom  mon  dow   command
  *  20  *    *    *     /home/grackle/Bin/tasks-daily.sh
Last edited by LockBot on Thu Mar 02, 2023 11:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Hawaiihemd
Level 4
Level 4
Posts: 409
Joined: Fri Sep 25, 2020 12:42 pm

Re: Crontab runs more than once? Or something..

Post by Hawaiihemd »

With the asterisk in the minute column you instructed cron to run the command on every minute of the 20th hour.
So it does as it was told.
User avatar
CommonGrackle
Level 1
Level 1
Posts: 25
Joined: Sat Dec 08, 2018 6:55 pm

Re: Crontab runs more than once? Or something..

Post by CommonGrackle »

Changed * to 0 (zero) -- thanks!
Locked

Return to “Scripts & Bash”