You are not logged in.

#1 2009-05-19 16:08:58

scv5
Member
Registered: 2008-10-19
Posts: 109

[solved] cronjobs and script not running.

brisbin33 suggested I use cron jobs to make sure offlineimap kept running for my mutt setup (copied from his as well), as he had problems with offlineimap and I am too.  So I'm running a bashscript (simple enough) that he wrote to check it was running and if not start it:

#!/bin/bash
# a simple script to restart offlineimap if it's died

if [ $(pgrep offlineimap | wc -l) -eq 0 ] ; then
  offlineimap
  exit 0
else
  exit 0
fi

exit 0

and then once a day in the early morning run a /usr/bin/pkill offlineimap. 


Simple enough.

My crontab -e:

*/3 * * * * /home/username/bin/offlineimap.cron
* 5 * * * /usr/bin/pkill offlineimap

the offlineimap.cron is executable.  Running the script doesn't seem to work.

I also changed the time of the pkill cron job to something a bit more current and let the time pass and noted that it didn't kill the running offlineimap that i manually started.

Any ideas?

Last edited by scv5 (2009-05-20 02:09:16)

Offline

#2 2009-05-19 16:47:25

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [solved] cronjobs and script not running.

a couple suggestions from my experience with this:

calling it *.cron could confuse cron, probably not but i'd change it to be safe, mine's ~/.bin/mailup

run each of these commands (the restart and the pkill) simply from CLI (with offlineimap running and not running) to make sure there are no errors and they're doing what's intended.

tail -f on on your cron logs as those commands go by, see if any errors show that could point you to the problem.  for completion here are my script and crontab -e as you can see i'm doing exactly as you.

#!/bin/bash
# a simple script to restart offlineimap if it's died

if [ $(pgrep offlineimap | wc -l) -eq 0 ] ; then
  offlineimap &
  exit 0
else
  exit 0
fi

exit 0
# fcrontab for user patrick

!mail(no),nolog(yes)
*/5 * * * * /home/patrick/.bin/mailup
*/15 * * * * /home/patrick/.bin/smartshuffle
0 5 * * * /usr/bin/pkill offlineimap
0 6 * * * /home/patrick/.bin/checkip
#0 */6 * * * * /home/patrick/.bin/shift_wallpaper

Offline

#3 2009-05-19 18:17:48

scv5
Member
Registered: 2008-10-19
Posts: 109

Re: [solved] cronjobs and script not running.

k, i changed the .cron to the name noted above..

cron log states:

19-May-2009 14:09  FILE /var/spool/cron/gnuisancev4 USER gnuisancev4 pid 28062 cmd /home/gnuisancev4/bin/mailup
19-May-2009 14:09  unable to exec /usr/sbin/sendmail -t, user -oem, output to sink null
19-May-2009 14:12  FILE /var/spool/cron/gnuisancev4 USER gnuisancev4 pid 29350 cmd /home/gnuisancev4/bin/mailup
19-May-2009 14:12  unable to exec /usr/sbin/sendmail -t, user -oem, output to sink null
19-May-2009 14:15  FILE /var/spool/cron/gnuisancev4 USER gnuisancev4 pid 30629 cmd /home/gnuisancev4/bin/mailup
19-May-2009 14:15  unable to exec /usr/sbin/sendmail -t, user -oem, output to sink null

The script runs on its own now, it didn't before.  But cron still won't start it.  a ps aux | grep offline, shows nothing.

Last edited by scv5 (2009-05-19 18:18:57)

Offline

#4 2009-05-19 18:30:51

benschni
Member
Registered: 2009-03-15
Posts: 5

Re: [solved] cronjobs and script not running.

Only a guess, as i don't know, what offlineimap is; does this program need X to be running? From my experience with cron, i remember, that it is not possible to run X programs (a very nasty characteristic of cron, it nearly drove me insane once, when i couldn't spot the error in my cron commands). Try to start offlineimap under virtual console to see what it's nature is. If cron does not work, try it with a simple script and use the sleep command.
Benjamin

Offline

#5 2009-05-19 18:54:25

scv5
Member
Registered: 2008-10-19
Posts: 109

Re: [solved] cronjobs and script not running.

offlineimap is a command line application that retrieves email for you from your email servers.  It doesn't require X.

Offline

#6 2009-05-19 20:05:31

area
Member
Registered: 2008-09-18
Posts: 43

Re: [solved] cronjobs and script not running.

i've always had to restart the cron daemon after any changes to my user tab.

Offline

#7 2009-05-20 02:09:02

scv5
Member
Registered: 2008-10-19
Posts: 109

Re: [solved] cronjobs and script not running.

ah,  i just appended:

>> /home/<username>/bin/errors 2>&1

to the crontab entry and that fixed it.

Offline

Board footer

Powered by FluxBB