LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-24-2010, 06:26 AM   #1
JacekZ
Member
 
Registered: Sep 2005
Location: Notts, England
Distribution: Debian 10
Posts: 71

Rep: Reputation: 15
cron ssh unison - inconsistent running


Hi,
Yet again I've lost hours struggling with a trivial quirk, so hoping for a pointer.

I have ssh with keys set up on machines on a home network so unison can run in batch mode to 2-way sync files on a laptop and netbook with a 'main' desktop (star pattern). It all works reliably in manual mode (where I can see the unison gui), but when invoked by crontab the behaviour is flaky, unison runs in invisible mode which is expected but synchronisation does not always occur.

The scheduled (invisible) version only effects a sync if I have previously (in the same computing session) run a visible instance of unison first. If I turn on a laptop without running the visible version of unison on it first, then cron runs the script I have written to invoke unison, but no synchronisation actually takes place (don't know how to tell if unison is actually invoked or not as it runs invisibly in that case). If I fire up unison in graphical mode (by manually running the same script -i.e. clicking on it), let it do a sync and close it, then the cron version runs invisibly but effectively until the next time 'something goes to sleep'.

Any ideas to explain the patchy behaviour, and what I need to do to make things work reliably in auto mode without first running unison in graphical mode?

I realise there could be a problem with remote machines trying to sync with the main machine at the same moment, but have tested and found the problem above occurs when only two machines are turned on (main and laptop for example).

Here's the script (tested with two versions of unison invocation - one is commented out). I add a line to copy a local file so I can test whether the script ran by seeing if the file is copied over. If it is I know the script is running at the correct intervals. The problem is not with running the script but with unison invocation or behaviour.

script (cronRunUnisonx):
Code:
#!/bin/bash
#/usr/bin/unison-2.27.57-gtk syncFiles -batch
unison syncFiles -batch
crontab entry
Code:
~$ crontab -l
# m h  dom mon dow   command
*/1 * * * * /home/j/Docs/Computing/Maintenance/Sync/cronRunUnisonx
running on Ubuntu Karmic 9.10

Thanks
 
Old 01-24-2010, 06:40 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
I'm a little confused about your crontab line:

Code:
*/1 * * * * /home/j/Docs/Computing/Maintenance/Sync/cronRunUnisonx
..are you trying to run it every minute ? Leaving the first '*' by itself will achieve this.

Have you checked /var/log/cron for any errors ?

cheers
 
Old 01-24-2010, 06:47 AM   #3
JacekZ
Member
 
Registered: Sep 2005
Location: Notts, England
Distribution: Debian 10
Posts: 71

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by kbp View Post
I'm a little confused about your crontab line:

Code:
*/1 * * * * /home/j/Docs/Computing/Maintenance/Sync/cronRunUnisonx
..are you trying to run it every minute ? Leaving the first '*' by itself will achieve this.

Have you checked /var/log/cron for any errors ?

cheers
Yes every minute. It works I think. There seem to be alternative ways to achieve the same end, but normally I would have */5, so it runs every five minutes, just changed it to 1 minute intervals for testing.

I don't have a /var/log/cron. Not sure where else it could be.
 
Old 01-24-2010, 04:25 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
You might need to redirect the output of the script to a file then:

Code:
*/1 * * * * /home/j/Docs/Computing/Maintenance/Sync/cronRunUnisonx >/tmp/unisoncron-$(date +%F-%s).log 2>&1
This should give you a log file with stdout and stderr for every run

cheers
 
Old 01-24-2010, 07:07 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
1. you'll need the absolute fullpath to unison in the cron run script. Yours is commented out and cron won't find it.
2. try 'mailx' as the cronjob owner and as root. If cron had an issue, it'll mail one or both of those users.

Does unison need to know where to find files to sync? If it's run from cron, again it'll need full paths to everything, or source the relevant info at the top of the script.
 
Old 01-25-2010, 04:04 PM   #6
JacekZ
Member
 
Registered: Sep 2005
Location: Notts, England
Distribution: Debian 10
Posts: 71

Original Poster
Rep: Reputation: 15
Well,
the redirect suggested by kbp didn't quite work, at least no output to be seen. Tried with another path setting in the redirect to user's home and that didn't work either. what does " 2>&1" do?

chrism01: I've tried full path in the unison script and no paths, both work as well or as badly as each other. I.e. they only run automatically after I have manually run the unison profile first within a given computing session. I know that crontab is supposed to have absolute path, but in this case it seems to make no difference. Just to be sure I tried putting in absolute paths absolutely everywhere that had a target file, but that only stopped unison from finding the preference files. I think the preference file is simply an argument for unison - unison then resolves where to locate that file by itself (the .unison folder in the user's home), so no path is required once unison is in control.

As for the 'mail to owner' suggestion, I think that is beyond me at this time. The crontab -e header doesn't offer an owner field, I believe that is found in some other higher level crontab file that I'm not familiar with.

I reckon this one has me beat. Manual sync will have to be good enough.
 
Old 01-25-2010, 04:29 PM   #7
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Maybe it needs to be in quotes so it doesn't get interpreted as an extra field ( I haven't tested this theory though.. )

Code:
*/1 * * * * "/home/j/Docs/Computing/Maintenance/Sync/cronRunUnisonx >/tmp/unisoncron-$(date +%F-%s).log 2>&1"
I'll see if I get a chance to test it today

cheers
 
Old 01-26-2010, 04:20 PM   #8
JacekZ
Member
 
Registered: Sep 2005
Location: Notts, England
Distribution: Debian 10
Posts: 71

Original Poster
Rep: Reputation: 15
Having lived with the flaky setup for a few more days, I now see that unison does run from cron, just not in an effective way right away. If I just leave things for about half an hour (remember that cron is running the unison profile every minute), it all comes right after some time. It is as though the computer was too busy to action the unison profile at first. Not sure how it is that unison run from cron is invisible but I guess it runs in another run-level. Maybe that other run level has a squeeze on resources? When unison is queuing up, system monitor reports those unison instances as "poll_schedule_timeout" in the waiting channel column - now I don't really know what that means but my guess is it indicates a delay. If that's right the next thing might be to work out how to give unison more priority or more room within the space it is trying to run in - assuming that can be done relatively simply. What do people think?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron not running sometimes yuiy88 Linux - Newbie 6 02-14-2008 02:37 AM
ssh cron just1812 Linux - Software 9 11-25-2007 04:28 PM
SSH Cron just1812 Linux - Software 3 11-23-2007 06:17 PM
Ssh Doesn't Work With Cron ? guano2 Linux - Networking 4 08-06-2005 12:57 AM
Cron Job not running ssh script karim0028 Linux - General 3 02-07-2005 12:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration