Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to set up a scheduled task via anacron but I would like to do so in user mode. How can I achieve this?

share|improve this question
    
If you want the task to run in user mode, you can do what i did and just prepend sudo -u <user> before the task in anacrontab –  Karthik T May 20 at 14:34

2 Answers 2

up vote 7 down vote accepted

You can set up a separate anacron instance to run in user mode:

  1. Create a .anacron folder in your home directory and in it two subfolders, etc and spool.

  2. Create a new anacrontab under ~/.anacron/etc with contents similar to the following:

    # /etc/anacrontab: configuration file for anacron
    
    # See anacron(8) and anacrontab(5) for details.
    
    SHELL=/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # period  delay  job-identifier  command
    1         10     testjob         test.sh
    
  3. Add the following line to your ~/.profile:

    /usr/sbin/anacron -s -t ${HOME}/.anacron/etc/anacrontab -S ${HOME}/.anacron/spool
    

Your user mode anacron should be up and running on next login.

share|improve this answer
    
Just to confirm, this runs the specified script as the user, so a whoami in the script will give the user name? –  Christoph Mar 2 at 19:50
    
hm yeah, on further inspection I don't see why not... –  Christoph Mar 2 at 20:12

This worked for me (thanks), but I didn't use the last step given in the answer:

"Then add the following line to your ~/.profile:"

I'm using Ubuntu Studio 12.10 Quantal and in my case instead of that last step I put that one liner here: "Applications Menu->Settings->Settings Manager" then in the Settings Manager under "Session and Startup" then the "Application Autostart" tab.

This is for those of us that are GUI users, because ~/.profile is only sourced by bash when it starts a log-in interactive shell (even ~/bashrc is not so useful since that is only sourced when bash is starting an interactive shell).

share|improve this answer
    
Mmh, I am a GUI user myself and the line in .profile has always worked fine for me (Ubuntu 12.04 here). –  Glutanimate Sep 12 '13 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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