Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 5641  / 1 Year ago, fri, april 14, 2023, 3:59:26

I'm using Ubuntu 11.10.



I've written a script, that synchronises a directory in ~ with a directory on /dev/sda4, using Unison. Before, I had this script running every five minutes with no problems, using crontab. Right now, I want to execute this script at startup, restart and shutdown only.



This is what the script looks like:



#!/bin/bash
unison -perms 0 -batch "/mnt/Data/Syncfolder/" "/home/myname/Syncfolder/"


I'd like the script to be run with mechanisms like Upstart, if possible. So I'd be happiest with a properly configured *.conf file in /etc/init.



Thanks in advance.


More From » bash

 Answers
1

After a lot of searching and asking here, I managed to get it working:



Before doing the following, make sure that you aren't using unison-gtk (the Unison GUI) as well. I've had a situation in which unison and unison-gtk conflicted. Remove unison-gtk via sudo apt-get remove unison-gtk, and disable Unison's old config files by renaming the containing folder: mv .unison .unison.old



When you've done that, it's time to move on.



First I ran the script as a superuser. I did that because Unison needs to be run once when you create a new script, to make some logging files. The Upstart-scripts are probably run as root, so it's best to do that too when you run the script for the first time:



sudo su



unison -perms 0 -batch "/home/MyName/Syncfolder" "/mnt/Data/Syncfolder" >> /var/log/unison.log



exit



Then, I ran: sudo gedit /etc/init/unison.conf. I pasted the following, and saved the file:



description "My File Sync"
author "My Name"
env HOME=/home/MyName
start on runlevel [0123456]

pre-start script
echo "Starts syncscript"
end script

post-stop script
echo "Ends syncscript"
end script

exec unison -perms 0 -batch "/home/MyName/Syncfolder" "/mnt/Data/Syncfolder" >> /var/log/unison.log


Restart and you're done.


[#40068] Friday, April 14, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tiowift

Total Points: 119
Total Questions: 113
Total Answers: 110

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
;