How to run a cron job only once?

I have a job which runs forever the moment it starts. So i want to start it only once after entering it into "crontab -e" file and saving it (or) whenever reboot happens.

How to achieve this?


If you want a command to run once at a later date, use the at command.

If you want a command to be run once at system boot, the correct solution is to use either:

  • system RC scripts (/etc/rc.local)
  • crontab with the @reboot special prefix (see manpage)

The latter is the only option for a non-root user.


You could use at(1) to run a job at some point in the future. However, if you want to run something on boot and it'll stay running by itself, maybe you want an entry in /etc/init.d/ for it? That would let you start it on boot.


A job that runs only once and runs forever till you tell it to die is called a "daemon". They are normally started via init scripts in /etc/init.d/.

If your job ends at some point and can be considered a one-off kind of job, then you may want to look at the at command. For instance if I wanted to run the find command at 10PM tonight and only this once I would do:

$ at 10PM
at> find /root > /root/find_results.list
at> <EOT>
job 3 at 2010-02-10 22:00