Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-09
5
Medium Priority
?
366 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:CRISTIANO_CORRADI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 672 total points
ID: 22676946
Hello CRISTIANO_CORRADI,

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' > cron.new
crontab cron.new

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

Regards,

sunnycoder
0
 

Assisted Solution

by:vrbiyani
vrbiyani earned 664 total points
ID: 22676977
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
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 664 total points
ID: 22676986
Simple, do it using at command. Please see

man at

http://www.rt.com/man/at.1.html
0
 

Author Comment

by:CRISTIANO_CORRADI
ID: 22677068
All your solutions are very interesting.  Thanks to all, I'll split the points.
0
 

Author Closing Comment

by:CRISTIANO_CORRADI
ID: 31504594
Thank you very much for your interesting suggestions! ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question