Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 4233966f4a
Fetching contributors…

Cannot retrieve contributors at this time

94 lines (80 sloc) 3.067 kb
#!/bin/sh -e
# Distributed under the terms of the BSD License.
# Copyright (c) 2011 Phil Cryer phil.cryer@gmail.com
# Source https://github.com/philcryer/lipsync
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
CONF_FILE=/etc/lipsyncd
###############
# DO NOT RUN if lipsyncd isn't running
###############
eval LIPSYNCD_PROCESS=`ps aux | grep lipsyncd.pid | grep -cv grep`
if [ $LIPSYNCD_PROCESS -eq 0 ]; then
exit 0
fi
###############
# source config, define logfile
###############
if [ -e $CONF_FILE ]; then
. $CONF_FILE
fi
LOG_FILE="/home/$USER_NAME/.lipsyncd/lipsyncd.log"
###############
# this from http://code.google.com/p/lsyncd/wiki/HowToExecAfter
# execute rsync just like it would have been done directly,
# but save the exit code
###############
IFS=
err=0
###############
# prevent data loss if there is a running rsync launched by lsyncd
###############
echo "`date "+%a %b %d %T %Y"` Cron: checking for running lipsync processes" >> $LOG_FILE
eval NB_RSYNC_PROCESS=`ps aux | grep rsync | grep "$REMOTE_HOST" | grep -v rsyncssh | grep -cv grep`
echo "`date "+%a %b %d %T %Y"` Cron: found $NB_RSYNC_PROCESS running lipsync processes" >> $LOG_FILE
if [ $NB_RSYNC_PROCESS -ne 0 ]; then
echo "`date "+%a %b %d %T %Y"` Cron: not running lipsync, another process already running" >> $LOG_FILE
exit 0
fi
###############
# run the rsync command to check server for updated files
###############
#/usr/bin/rsync $@ || err=$?
rsync -rav --stats --log-file=/home/$USER_NAME/.lipsyncd/lipsyncd.log -e "ssh -l $USER_NAME -p $SSH_PORT" --delete $REMOTE_HOST:$REMOTE_DIR $LOCAL_DIR
###############
# this writes source -> destination details to lipsyncd.log
###############
eval LOCAL_HOST=`hostname`
echo "`date "+%a %b %d %T %Y"` Cron: updated $REMOTE_HOST -> $LOCAL_HOST" >> /home/$USER_NAME/.lipsyncd/lipsyncd.log || true
###############
# get line number of last run
###############
LAST_RUN=`cat /home/$USER_NAME/.lipsyncd/lipsyncd.log | grep --line-number "] receiving file list" | tail -n1 | cut -d':' -f1`
###############
# count deleted files since LAST_RUN
###############
DELETED_FILES=`cat /home/$USER_NAME/.lipsyncd/lipsyncd.log | sed -n ''$LAST_RUN',$p' | grep "*deleting "| wc -l`
###############
# popup if we've had deleted files on this run
###############
if [ "${DELETED_FILES}" -ne '0' ]; then
if [ "${DELETED_FILES}" -eq '1' ]; then
/usr/local/bin/lipsync-notify "$DELETED_FILES file deleted"
else
/usr/local/bin/lipsync-notify "$DELETED_FILES files deleted"
fi
fi
###############
# count transfered files
###############
TOTAL_TRANS=`cat /home/$USER_NAME/.lipsyncd/lipsyncd.log |grep "Number of files transferred" | tail -n1 | cut -d" " -f8`
if [ "${TOTAL_TRANS}" -gt '0' ]; then
if [ "${TOTAL_TRANS}" -eq '1' ]; then
/usr/local/bin/lipsync-notify "$TOTAL_TRANS file synced"
else
/usr/local/bin/lipsync-notify "$TOTAL_TRANS files synced"
fi
fi
###############
# returns the exit code of rsync to lsyncd
###############
exit $err
Jump to Line
Something went wrong with that request. Please try again.