Linux Execute Cron Job After System Reboot

I am on Red Hat Enterprise Linux server. Is there is an easy way to run script or command at boot time after fresh reboot command? How can I execute cron job on Linux after system restart?

crontab is the program used to install, deinstall, or list the tables used to drive the cron daemon in Vixie Cron. Each user can have their crontab. You or user can use the crontab command to edit cron jobs. This page shows how to run cron job after Linux system reboot.

Linux execute cron job after system reboot

The crontab command maintains crontab files for individual users. One can install or remove cron jobs as per needs.
Linux Execute Cron Job After System Reboot

Running job at startup (boot time)

You need to use special string called @reboot. It will run once, at startup after Linux reboot command. The syntax is as follows:

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

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/
It i a super-simple way to run scripts on boot using cron jobs.

How to run a cron job automatically after server reboot

Say your script needs to be run only after 5 minutes. For example: reboot + 5mintues. The syntax is as follows:
@reboot sleep 300 && /home/wwwjobs/
The sleep command to add delay for a specified amount of time. In this example, 600 seconds and after that time gets executed at boot time.

Start crond automatically at boot time

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:
# chkconfig crond on
## Commands to start/stop/restart crond for Linux Execute Cron Job ###
# service crond restart
# service crond start
# service crond stop

Under Debian / Ubuntu Linux use update-rc.d as follows to turn on service on boot:
# update-rc.d cron defaults
If you are using modern distro with systemd, try the following systemctl command # systemctl enable crond.service
### this to start/stop/restart crond on systemd enabled distro such centos 7.x/debian/ubutnu/arch ###
# systemctl start crond.service
# systemctl stop crond.service
# systemctl restart crond.service
# systemctl status crond.service

For Debian/Ubuntu Linux with systemd, try:
$ sudo systemctl enable cron.service
$ sudo systemctl start cron.service
$ sudo systemctl stop cron.service
$ sudo systemctl restart cron.service
$ sudo systemctl status cron.service

Save and close the file. For further information read out tutorial on cron jobs.


This page showed how to run and execute cron job after system rebooted. For more info see this page here.

This entry is 10 of 16 in the Linux Cron Jobs Howto & Tutorial series. Keep reading the rest of the series:
  1. What is cron on a Linux or Unix-like systems?
  2. How To Add Jobs To cron Under Linux or UNIX?
  3. Verify crond Daemon And Cronjobs Are Running
  4. Start Restart and Stop The Cron or Crond Service
  5. List / Display All Cron Jobs
  6. Linux / UNIX Crontab File Location
  7. Change Crontab Email Settings ( MAILTO )
  8. Disable The Mail Alert By Crontab Command On a Linux or Unix-like Systems
  9. At What Time Cron Entries In cron.daily, cron.weekly, cron.monthly Run?
  10. Execute Cron Job After System Reboot
  11. Setup and Run PHP Script As A Cron Job
  12. Run crontab job every minute on a Linux or Unix-like system
  13. Running crontab (cron jobs) Every 10 Minutes
  14. Cron Job Script Execution on the Last Day of a Month
  15. Execute / Run crontab (cron jobs) every 1 minute
  16. Ubuntu create cron.log file

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 14 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
14 comments… add one
  • Linuxrebel Feb 17, 2009 @ 21:26

    OK, But some caveats here.

    1. Only works after a reboot. If you do a shutdown, or if the box crashes (as in plug vs vacuum) …. and then start, it doesn’t get run.

    2. The @reboot command is not universal, especially missing on systems running micro or embedded Linux.

    3. There is an alternate. the file /etc/rc.local is a place were you can place a command string to be run on boot, regardless of the means by which the system went down. Yes I know many Linux purists in favor of SysV style init scripts. However for a quick on liner it’s perfect. Here also gets run if you do a warm restart (as in go to init level 1 and then back to 3 or 5). Best this works across a very wide if not all spectrum of Linux systems. Anything in this file is always the last thing to run prior to login prompt appearing.

    4. Write an init script, and put it in /etc/init.d with the appropriate run levels and timing. Harder to do and get right, somewhat, but it is the correct way to create an init entry. It also would allow for you to fine tune the timing. (need to run this job before something else gets started? Use this method)

  • Ashwani Feb 21, 2009 @ 10:36

    linuxrebel is just looks ..right…but will an normal .sh script run on boot up if we put it in specified run level script like rc3.d ?…or what we need to do to follow what Linuxrebel said above??

    Thanks Vk & Lr

  • pasourus Feb 15, 2012 @ 7:22

    The @reboot command not working. Finally got this and using for my Wordpress Site,
    # touch /etc/init.d/memcached
    # echo ‘#!/bin/sh -e’ >> /etc/init.d/memcached
    # echo ‘/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody -l localhost’ >> /etc/init.d/memcached
    # chmod u+x /etc/init.d/memcached
    # echo ‘/etc/init.d/memcached’ >> /etc/rc.local

  • Moray Feb 23, 2012 @ 10:59

    On CentOS 5.6, an /etc/cron.d/rebootlog crontab containing

    @reboot root date >> /var/tmp/reboot.log

    Is run when the system restarts after the commands “reboot”, “shutdown -r”, “shutdown -h”, “halt” and after a power failure. I did not find a shutdown method where the job was not run when the system restarted.

  • vedagiri Apr 9, 2012 @ 7:34

    how i check whether the cron job is running or not?

    • Nkaronji Sep 25, 2012 @ 20:22

      If Cron is running a custom script then in your script you can write to a log file. Something like echo “Starting cronjob + timestamp” and echo “Successfully finished cron job + timestamp”

  • Philarete Dec 8, 2012 @ 17:42

    With grep, it’s a little bit different. For example, to move every files including a given type of datas:
    grep ‘<div id=' ./* | cut -f 1 -d":"|xargs -I {} mv {} ../YOUREP/{}

  • camypaj Sep 16, 2013 @ 6:37

    great tip, tnx! Made my day & solved a problem I had.. :)
    Btw, I’ve just noticed a typo: command on redhat is “chkconfig” instead of “chekconfg”.

  • IIIII Jun 14, 2014 @ 17:50

    May want to fix the spelling on – chkconfig

  • vamsi Jun 30, 2014 @ 7:38

    I used “chkconfig crond on”
    Its working fine, thanks…

  • Informant Apr 15, 2015 @ 14:02

    Just an FYI…there’s a typo in the header of the word “startup”: “Running job at statup (sp.) (boot)”.

  • kevin Jan 7, 2016 @ 5:55

    how to run certain script after 5mins of reboot

    • P Mar 11, 2016 @ 9:41

      @reboot sleep 300;

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum