Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Linux/Create a Crontab via Script

December 30, 2018

Create a Crontab via Script

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

Have content delivered to your mail. Subscribe below.

About Me

I'm Ulysses, Cloud Engineer at Cardinal Health based in Columbus. This blog is about Linux and Cloud technology. When off the grid, I enjoy riding my electric skateboard. I've surfed, snowboarded and played the saxophone in the past. I hope you find this website helpful. It's powered by WordPress and hosted on AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021