• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Create a Crontab via Script

December 30, 2018

How do you create a crontab entry via a Bash script? That’s a good question. Here is one solution:

(crontab -l 2>/dev/null; echo "* 11 * * * /path/to/job -with args") | crontab -

(crontab -l 2>/dev/null; echo "* 11 * * * /path/to/job -with args") | crontab -

If you want to run it as a specific user, use the following:

(crontab -l -u user 2>/dev/null; echo "* 11 * * * /path/to/job -with args") | crontab -

(crontab -l -u user 2>/dev/null; echo "* 11 * * * /path/to/job -with args") | crontab -

Filed Under: Linux Tagged With: bash, cron, user

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023