1

I'm using Ubuntu 16.04.1 LTS. I have installed incron and added root to incron.allow.

Normally I use sudo incrontab -e to add an incron job with the editor.

I need a command which can be run from a script which will add this line to the incrontab directly:

/home/ci-server/DB_Backups IN_MOVED_TO mv /home/ci-server/DB_Backups/$# /home/backup/$#

Once this line is shown via sudo incrontab -l everything should be good to go.

I have found a couple of examples using cron but very little information exists for incron.

ekcell
  • 105
  • 2
  • 11
  • 1
    Looking at the man page for [incrond](https://linux.die.net/man/8/incrond) you should be able to append your command to a file in `/etc/incron.d` or `/var/spool/incron`. So something like `echo "/home/ci-server/DB_Backups IN_MOVED_TO mv /home/ci-server/DB_Backups/$# /home/backup/$#" >> /var/spool/incron/ekcell.cron` – 0x5453 May 09 '17 at 20:41

1 Answers1

0

You can do this by creating a script named incron.sh with the following contents:

#create a new file named incron.txt that lists the incron job
sudo echo '/home/ci-server/DB_Backups IN_MOVED_TO mv /home/ci-server/DB_Backups/$# /home/backup/$#' > /home/ci-server/scripts/incron/incron.txt
#add the job(s) listed in our newly created incron.txt to the incrontab
sudo incrontab -u root /home/ci-server/scripts/incron/incron.txt
ekcell
  • 105
  • 2
  • 11