Is there any way to insert an event in the crontab, and to cut off that row after that event is fired?

Good morning!

Often, when I have the need to launch a Unix Korn Shell script (which has a duration of about 15 hours), of course I call it from crontab, for example in the crontab file I add the following row:
30 18 * * * $HOME/system/startscript/aggregate.ksh

The risk is that I forget to remove that row after the 18:30 (hour in which the script aggregate.ksh is launched), so that after 24 hours the script will be executed again!

Is there any way to make that row disappear after that the event is fired?
Who is Participating?
sunnycoderConnect With a Mentor Commented:

you can either add a check in your script to make sure that rerun is intended - e.g. each run creates a file and successive run checks for presence of the file. If file is present, next execution is aborted. For next sucessful cron run you need to remove the file manually.

Other alternative is to remove the cron job after execution

crontab -l | sed '/aggregate.ksh/d' >

you can add the above script as cron job after aggregate.ksh has executed or call it from aggregate.ksh itself


vrbiyaniConnect With a Mentor Commented:
Crontab itself does not offer a utility to remove the job after it is done. A couple of alternatives (Which again you may be aware of):

1) Specify the date and month also in the job, so that it will be executed only once and not again the next day. Just specifying the time is probably not a very good way to run the job
2) In the script which you are running, add a line to rename/move itself to other location. So that the job running next day does not find it
omarfaridConnect With a Mentor Commented:
Simple, do it using at command. Please see

man at
All your solutions are very interesting.  Thanks to all, I'll split the points.
Thank you very much for your interesting suggestions! ;-)
All Courses

From novice to tech pro — start learning today.