Friday, 19th April 2024

Comment posted How to add cron jobs from command line or bash scripts / Add crontab jobs in a script by .

Recent comments by

Share this on:

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

No Responses to “…”

  1. Wellwet says:
    Firefox 5.0 Firefox 5.0 Windows Vista Windows Vista
    Mozilla/5.0 (Windows NT 6.0; rv:5.0) Gecko/20100101 Firefox/5.0

    There is a better way to edit crontab jobs. Just append your commands to /var/spool/cron/ file where is the user which cron jobs you are going to modify. Make sure your cron user is allowed to wrtie to that file (by default it belongs only to root).

    View CommentView Comment
    • Wellwet says:
      Firefox 5.0 Firefox 5.0 Windows Vista Windows Vista
      Mozilla/5.0 (Windows NT 6.0; rv:5.0) Gecko/20100101 Firefox/5.0

      I meant /var/spool/cron/username file (wordpress engine suddenly does not allow to insert text in ‘less-than’ and ‘more-than’ braces)

      View CommentView Comment
      • admin says:
        Epiphany 2.30.6 Epiphany 2.30.6 Debian GNU/Linux x64 Debian GNU/Linux x64
        Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+ Debian/squeeze (2.30.6-1) Epiphany/2.30.6

        Thanks a lot,

        This tip is helpful. I might use this one as well it’s more readable kind of way for sure. Though it will require root user 😉

        Hope to see you around,

        Best!
        Georgi

        View CommentView Comment
  2. Chris says:
    Google Chrome 15.0.874.121 Google Chrome 15.0.874.121 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2

    Thanks 🙂

    View CommentView Comment
  3. Seth Fuller says:
    Google Chrome 18.0.1025.152 Google Chrome 18.0.1025.152 Windows XP Windows XP
    Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19

    Thanks so much. This helped me a lot. How would you write the script in reverse to remove the same cron job?

    View CommentView Comment
  4. John says:
    Firefox 13.0.1 Firefox 13.0.1 GNU/Linux x64 GNU/Linux x64
    Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1

    I was recently wondering the same thing as I’m automating a bunch of systems and need to add quite a few cronjobs and did not want to overwrite anything they currently had. So I found this page. The method I used however was this (using your example cronjob):

    crontab -l|sed ‘$a*/5 * * * * /root/myscript.sh’|crontab –

    In this way, you obtain the previous values using crontab -l and append */5 * * * * /root/myscript.sh to the entries using sed and then pipe the entirety back into crontab in one fell swoop without having to mess with temporary files.

    The best part, is this can be modified easily to alter cronjobs for different users (if you have permission) using the -u flag for crontab. Like so:

    crontab -u john -l|sed ‘$a*/5 * * * * /root/myscript.sh’|crontab -u john –

    View CommentView Comment
  5. Dilip says:
    Google Chrome 35.0.1916.153 Google Chrome 35.0.1916.153 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

    Cool .. thats awesom. 

    View CommentView Comment
  6. admin says:
    Google Chrome 40.0.2214.115 Google Chrome 40.0.2214.115 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36

    Alternative way to add to crontab user with existing cron jobs is to use something like:

    crontab -l | { cat; echo “0 0 1 * * rsync -qt rsync://rsync.blitzed.org/countries/zz.countries.nerd.dk.rbldnsd \
    /usr/local/etc/powerdns/zz.countries.nerd.dk.rbldnsd && \
    /usr/bin/pdns_control rediscover > /dev/null”; } | crontab –

    View CommentView Comment