I use a cron job to call offlineimap every 2 minutes:

*/2 * * * * /usr/bin/offlineimap > ~/Maildir/offlineimap.log 2>&1

I needed to kill the cron job to fix a problem. How can I then restart the cron job (without rebooting)? I found this 'solution' online:

mylogin@myhost:~$ sudo /etc/init.d/cron restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service cron restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop cron ; start cron. The restart(8) utility is also available.
cron stop/waiting
cron start/running, process 26958

However, using ps -ef | grep ..., I don't see the job... What's wrong?

  • Which job can't you see?
    – Spack
    May 4, 2013 at 22:41
  • 1
    Open your crontab, comment out that job, perform your maintenance and then uncomment it...
    – jasonwryan
    May 4, 2013 at 23:56

3 Answers 3


Cron approach

If you have sudo privileges you could stop/start the cron service. I believe that's what that solution you found online was explaining.

Depending on which Linux distro you're using you could either do these commands:

# redhat distros
$ sudo /etc/init.d/crond stop
... do your work ...
$ sudo /etc/init.d/crond start

Or do these commands:

# Debian/Ubuntu distros
$ sudo service cron stop
... do your work ...
$ sudo service cron start

Lock file type approach

You could also put a "dontrunofflineimap" file in say the /tmp directory when you want the offlineimap task to hold off and not run for a bit.

The process would work like this. You touch a file in /tmp like so:

touch /tmp/dontrunofflineimap

The cron job would be modified like so:

*/2 * * * * [ -f /tmp/dontrunofflineimap ] || /usr/bin/offlineimap > ~/Maildir/offlineimap.log 2>&1

While that file exists, it will essentially block the offlineimap app from running. When you want it to resume, simply delete the /tmp/dontrunofflineimap file.


Another solution is to edit the crontab and comment-out the job to disable it. That's a little nicer as cron might be scheduling other jobs as well.

The following command helps:

crontab -e

If it's root's crontab and not the user's:

sudo crontab -e

To comment-out the job, add a # at the start of the line. Like this:

# */2 * * * * /usr/bin/offlineimap > ~/Maildir/offlineimap.log 2>&1

You can read http://tutscode.com/how-to-use-crontab-in-linux/ to get more information about crontab.

  • Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – slm
    Dec 1, 2014 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.