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:
@reboot
special prefix (see manpage)The latter is the only option for a non-root user.
at now
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.
kill
(assuming you've got the permissions to do so, which you do for your own processes). Making an init script is really easy. Look in /etc/init.d/
for a script that isn't very long and model yours after it, or google for making init scripts (your distribution)
.
Feb 10, 2010 at 18:47
/etc/init.d/skeleton
on openSuSE) that you can adapt for your use.
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
Have a look at the at command