# Cannot get unison to run from cron (solved)

## Bigun

I'm attempting to setup my backup schedule by using unison.  I'm trying to get the unison socket service to start via cron on the backup server.  I have vixie-cron installed and running.  Here is what the crontab looks like:

```
projector ~ # crontab -l

# DO NOT EDIT THIS FILE - edit the master and reinstall.

# (/tmp/crontab.XXXX4uevWD installed on Wed Jan 25 07:17:17 2012)

# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)

MAILTO=xxxx@xxxxx.com

#minute hour dayofmonth month dayofweek command

19 7 * * * /root/start_unison.sh
```

The unison script has the correct permissions to be executable:

```
projector ~ # ls -la /root/start_unison.sh

-rwxrwx--- 1 root root 40 Jan 25 06:54 /root/start_unison.sh
```

Here is the contents of the script:

```
projector ~ # cat start_unison.sh

#!/bin/bash --

unison-2.27 -socket 5377
```

I set the crontab to execute the script, watch the process list, and nothing happens.  What am I doing wrong?

----------

## Jaglover

Try using full path to unison in your script.

----------

## Bigun

```
projector ~ # ls -la /usr/bin/unison-2.27

-rwxr-xr-x 1 root root 1308568 Jan 23 15:48 /usr/bin/unison-2.27

projector ~ # cat start_unison.sh

#!/bin/bash --

/usr/bin/unison-2.27 -socket 5377
```

Just tried it:

```
projector ~ # crontab -l

# DO NOT EDIT THIS FILE - edit the master and reinstall.

# (/tmp/crontab.XXXX9A2DBu installed on Wed Jan 25 08:15:17 2012)

# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)

MAILTO=bigun@pwnedclips.com

#minute hour dayofmonth month dayofweek command

18 8 * * * /root/start_unison.sh
```

```
projector ~ # date

Wed Jan 25 08:19:29 EST 2012

projector ~ # ps -A | grep unison

projector ~ #
```

No dice

----------

## Jaglover

Then it has to be permissions problem, now when I think of it I'm not sure cron can run your script with root rights. Not sure if cron can even descend to /root. Perhaps somebody with better knowledge about cron inner workings will chime in.

Have you tried to run this command from crontab directly, without wrapping it into a script.

BTW,  *Quote:*   

> Unison is a user-level program: there is no need to modify the kernel or to have superuser privileges on either host.

  Why are you trying to run it as root anyway?

----------

## Bigun

 *Jaglover wrote:*   

> Then it has to be permissions problem, now when I think of it I'm not sure cron can run your script with root rights. Not sure if cron can even descend to /root. Perhaps somebody with better knowledge about cron inner workings will chime in.
> 
> Have you tried to run this command from crontab directly, without wrapping it into a script.
> 
> BTW,  *Quote:*   Unison is a user-level program: there is no need to modify the kernel or to have superuser privileges on either host.  Why are you trying to run it as root anyway?

 

I've tried running it directly with the same result.

As far as why I'm running as root is really for the purpose of permissions access.  I'm attempting to setup a backup script with a variety of permission levels, owners, and groups.

----------

## jormartr

Try setting the log and logfile variables, maybe unison writes something there before dying...

----------

## Bigun

 *jormartr wrote:*   

> Try setting the log and logfile variables, maybe unison writes something there before dying...

 

Oddly enough, as I was about to write this post I tried that and it worked, all I did was direct the output to a log like so:

```
unison -[options] &> /tmp/unison.log
```

and it worked.  Thanks!

----------

## jormartr

Maybe unison expects an interactive terminal... could you try the dumbtty option (or something like that).

----------

## Bigun

 *jormartr wrote:*   

> Maybe unison expects an interactive terminal... could you try the dumbtty option (or something like that).

 

There's a -batch option that does a non-interactive way of syncing the files, but apparently will crap out if there is any output.

----------

