September 18

Linux: Run a Cron Job After System Reboot

For AIX, CentOS, Debian / Ubuntu

Use crontab program to edit cron jobs.

Running job at statup (boot)

You need to use special string called @reboot. It will run once, at startup after reboot command.

@reboot /path/to/job
@reboot /path/to/shell.script
@reboot /path/to/command

This is an easy way to give your users the ability to run a shell script or command at boot time without root access. First, run crontab command:
$ crontab -e
# crontab -e -u UserName
# crontab -e -u vivek

Run a script called /home/vivek/bin/
@reboot /home/vivek/bin/
You also need to enable crond service via sys v / BSD init style system. Under RHEL / CentOS / Fedora, you need to use chkconfig (ntsysv) command to enable crond on boot:
# chekconfg crond on
Under Debian / Ubuntu Linux use update-rc.d as follows to turn on service on boot:
# update-rc.d cron defaults

Save and close the file.

By: Nixcraft

Copyright 2021. All rights reserved.

Posted September 18, 2013 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B