4

I want a special command to be lauched everyday, but dont want to put it in the /etc/cron.d/ because its a user specific user!

pg@pipoTower: ~$ crontab -l
# m h  dom mon dow   command
0 0 * * * updatedb -l 0 -o ~/.externalharddisk.db -U /var/autofs/removable/usbData

The crontab -e command which puts the file in /var/spool/cron/crontabs/userName

but dont know why its not called by anacron....

usr@Tower: ~/$ cat /etc/anacrontab 
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries
1       5       cron.daily      run-parts --report /etc/cron.daily
7       10      cron.weekly     run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly    run-parts --report /etc/cron.monthly

1 Answers1

11

I've found two workarounds for this...

Option 1: Have cron.daily script run as non-root user

Scripts in /etc/cron.daily will run as root, but root doesn't need a password to run as someone else. So put a script there that does something like this:

su myuser -c "/home/myuser/dostuff.sh"

The main drawback if you need to be root to set this up.

Option 2: Set up a personal anacron

Create your own anacron script directories, eg ~/.anacron/daily, ~/.anacron/weekly and ~/.anacron/monthly. Put your daily scripts in the daily directory.

Then create your own anacrontab file, eg ~/.anacron/anacrontab. And make it say this:

1   5   cron.daily  run-parts --report /home/myuser/.anacron/daily
7   10  cron.weekly run-parts --report /home/myuser/.anacron/weekly
@monthly    15  cron.monthly    run-parts --report /home/myuser/.anacron/monthly

Also make a spool directory for your anacron task, eg ~/.anacron/spool.

Finally you need make anacron run. Use a frequent cron job for this. Run crontab -e and add

* * * * * /usr/sbin/anacron -t /home/myuser/.anacron/anacrontab -S /home/myuser/.anacron/spool

This will run anacron with your config every minute and if a job is due anacron will run it. You can make it less frequent if you like, every hour might be good enough for most users.

ge32
  • 319