Linux: Crontab notes for different users – run a cron job every time a system reboots


Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Each user has its own crontab in Linux. Root crontab is only available to root and cannot be modified by other users. To edit your non-root crontab:
crontab -e

To list available crontab:
crontab -l

To delete:
crontab -r

Privileged users can access others crontab:
crontab -u

Run cron jobs as a different user:
su - <user> -c <command or script>
Depending on your default editor crontab will either open in vi or nano. Crontab line format should look like:
# m h dom mon dow user command
Under which you will have to specify when your cron job should run:
m: minute of the day, from 0 to 59
h: hour of the day, from 0 to 23
dom: day of month, from 1 to 31
dow: day of week, from 1 to 7
user: user your cron job should run as
command: command or script that should run

Root has access to two crontabs. One is accessible through crontab and the other can be opened in your editor: vi /etc/crontab or nano /etc/crontab. Systemwide cron jobs should be added to /etc/crontab which take precedence over your regular cron.

A sample cron job should look like the following line. Here is a line I have in my crontab to sync time with external time servers:
# m h dom mon dow user command
01 0 * * * root ntpdate us.pool.ntp.org

This cron job will sync time at 12:01 AM every night with pool.ntp.org

Tip: to create a cron job to run every time your system reboots (game servers, etc.) start your line with @reboot:
@reboot /home/user/script
Notice that you don’t need to specify anything but @reboot and path to executable. Regular and privileged users can both use this command.

Other commands:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 (0 0 1 1 *)
@annually = run at midnight Jan 1(0 0 1 1 *)
@monthly = run at midnight on the first day of every month (0 0 1 * *)
@weekly = run at midnight every Sunday (0 0 * * 0)
@daily = run at midnight every day (0 0 * * *)
@midnight = run at midnight (0 0 * * *)
@hourly = run on the first second of every hour (0 * * * *)

4 thoughts on “Linux: Crontab notes for different users – run a cron job every time a system reboots


  1. Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
    Jakub says:

    Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

    Thank you. I’m beginner with Linux and your guide saved me a lot of time.

  2. Pingback:
    Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
    marinov.biz

  3. Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
    som says:

    Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

    The crontab for triggering a job at 12am midnight is not working. following is the syntax that i used in my crontab.
    0 0 * * * command_to_be_triggered

    Please help me with this.


    • Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
      Ali says:

      Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/3/d98111892/htdocs/insanelabs/htdocs/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

      That should work just make sure your spacing is right. What if you do 01 0 * * * and see if it runs at 12:01 AM.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.