Anacron for specific user

Few days ago I was working to set up a backup reminder process for myself. After having few searches I observed anacron fits the best to solve my requirement- sending notification at certain frequency and at my availability too. The issue is sytem’s default /etc/anacrontab by default works for root user. We can execute a job for other users too by adding new group and user to the same. When I did that I saw though the execution time has been logged successfully but that job was silently failing to notify me. So I left that approch and setup a separate anacron instance to run for my profile.

Here are the steps-

1. Create anacron in home directory /home/kuntal

$ mkdir .anacron

2. Create 2 directories etc and spool there

$ mkdir .anacron/etc .anacron/spool

3. Copy the default anacrontab in etc directory

$ cp /etc/anacrontab .anacron/etc/.

4. Modify the same as required. Mine is below

# /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

7       10      weeklyreminder     /etc/weekly-reminder.bash

The job description is in the following format.

period delay job-identifier command Where

Field 1 is Recurrence period– Here it’s supposed to run on weekly basis.
Field 2 is Delay– X number of minutes anacron should wait before executing the job after the the machine starts.
Field 3 is Job identifier– unique name referring to a particular job.
Field 4 is command– script to be executed.

5. Now add the instance in profile i.e. /home/kuntal/.profile

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

That’s all to execute that job from my login.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s