3

I'm using unison to synchronise data to a server, and I've recently created a cronjob for this. The cronjob is running at startup and saves the output to a log file. (additional info below).

The problem I'm having is that unison has quite a lot of output, and I'd like to only save the summary to the log file. Is there a way to do that? I haven't found a way to make unison less verbose, so I thought maybe the output can be filtered somehow - I just wouldn't know how.

Thanks!

Additional info:

Right now, the log file ends up looking like this:

Contacting server...
Connected [//theserver//share/HDA_DATA/elrudi -> //thelaptop//home/elrudi]
Looking for changes
\ syncAll/Code/Aptana/T...avascript library code assist.txt

\ syncAll/Code/develope...nk/20070607 contacten (INDEX).xls

\ syncAll/Code/sourcefi...okexport/photos/10152112061815397

| syncAll/Code/Python/d...rawable-hdpi/ic_action_search.png

(... many many lines ...)

| syncAll/Work/2008_10 ...profile/StandardLastprofil_H0.xls

| syncAll/Work/2008_10 ...n/Load Profiles/Lastprofil_H0.xls

Waiting for changes from server
Reconciling changes
changed  ---->            syncAll/scriptfile1.sh 
Propagating updates
UNISON 2.40.102 started propagating changes at 12:07:31.55 on 07 Oct 2015
[BGN] Updating file syncAll/scriptfile1.sh from /home/elrudi to //theserver//share/HDA_DATA/elrudi
100%  00:00 ETA

[END] Updating file syncAll/scriptfile1.sh
100%  00:00 ETA

UNISON 2.40.102 finished propagating changes at 12:07:31.61 on 07 Oct 2015
100%  00:00 ETA

Saving synchronizer state
Synchronization complete at 12:07:36  (1 item transferred, 0 skipped, 0 failed)

I'd want to ditch the lines starting with |, /, -, or \ (the spinning bar indicating a process is not finished yet).

More additional info:
crontab -e shows

@reboot /home/elrudi/sync.sh -batch 60 >> /home/elrudi/.cronjobs.log 2>&1   

The sync.sh script checks whether the server is locally reachable or remotely, and runs the appropriate unison command. The -batch parameter is added to make unison run without user input, and the 60 is a waiting time (to make sure unison does not run before a connection is available).

3
  • Don't immediately redirect do the log file, but pipe through sed or grep first to filter the output.
    – Nephente
    Oct 7, 2015 at 10:41
  • have you tried the -terse option to unison? (never tried it --- but the manual says "-terse: suppress status messages")
    – Rmano
    Oct 7, 2015 at 13:14
  • Hmmm -terse is not bad either. It's a bit too quiet for my taste, but it'd have done the job too, thanks for the suggestion!
    – ElRudi
    Oct 7, 2015 at 18:58

1 Answer 1

6

When you call unison in your sync.sh script call it as follows:

unison ... 2>&1 | grep -vE '^[\|/-]|^$'

This will remove (-v) all line that match the regual expression: All line beginning with one of those characters: \|/-, or complete empty lines (^$).


Edit: If you want the cronjob to be filtered, use:

@reboot /path/to/sync.sh -batch 60 2>&1 | grep -vE '^[\|/-]|^$' >> /path/to/logfile
6
  • Nice, I was trying to figure out a way with sed, which I'm quite new to, and was tying my brain in knots about escaping special characters. Good old grep can save a lot of headaches from over complicating things!
    – Arronical
    Oct 7, 2015 at 11:05
  • @kos True, but stderr of unison itself would then not be filtered with grep. If that is desired: ok. I don't know unison, but some tools send teihr process animation via stderr.
    – chaos
    Oct 7, 2015 at 11:12
  • Thanks, that makes sense :) As it has come up: is there a way to output the errors, if any occur, to a separate log file?
    – ElRudi
    Oct 7, 2015 at 12:22
  • Ah, sorry, I'm so silly, for some reason I thought stderr redirection came before stdout redirection in OP's command. Indeed that's correct, removed my comments
    – kos
    Oct 7, 2015 at 12:39
  • Ah and, it is not possible to do the grep filtering at the cronjob? I ask as the script is also used to perform a manual sync, during which all output is appreciated. If it is indeed not possible I guess I could add a parameter to the script to toggle filtering, but I'd prefer to have it at the cronjob level, if that makes sense
    – ElRudi
    Oct 7, 2015 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .