2

I'm trying to add a cron job without actually opening vim or nano. Something like this:

$ crontab -e << echo '* 0/10 * * *  some command'

I'm seeing stuff online like this and this, but honestly it's kinda confusing.

Zanna
  • 72,312
Laura
  • 231

1 Answers1

4

First create make a copy of your user's crontab file using:

crontab -l > ${USER}_crontab

then you can easily work with username_crontab as it's a normal file, edit it or redirect anything to it in different ways.

For example append a new job:

echo '* 0/10 * * *  some command' >> ${USER}_crontab

then install the file using:

crontab ${USER}_crontab

You can also do it all in once like this:

cat <<< "* * * * *  cmd1" > my_jobs; crontab my_jobs

or:

cat > my_jobs <<E                   
* * * * *  cmd1
* * * * *  cmd2
E

crontab my_jobs
Ravexina
  • 57,256