color and logs
This commit is contained in:
parent
b29cf27a05
commit
2147ceebd6
@ -38,8 +38,9 @@ sync() {
|
|||||||
# in this form rsync receive only data from source 1>$syncloopfile 2>&1
|
# in this form rsync receive only data from source 1>$syncloopfile 2>&1
|
||||||
rsync -ni -aPu --progress --out-format="%i ${GREEN}%n%L${ENDCOLOR} %''b" --log-file=$logfile -e ssh $otheropts $src $dest | \
|
rsync -ni -aPu --progress --out-format="%i ${GREEN}%n%L${ENDCOLOR} %''b" --log-file=$logfile -e ssh $otheropts $src $dest | \
|
||||||
grep -e "[<|>]" | \
|
grep -e "[<|>]" | \
|
||||||
sed -E "s~<(\w|\W){10}~Sending to ${dest}~g" | \
|
sed -E "s~<(\w|\W){10}~\\${PURPLE}Sending\\${ENDCOLOR} TO ${dest}~g" | \
|
||||||
sed -E "s~>(\w|\W){10}~Receiving from ${src}~g" | xargs -0 printf 1>>$syncloopfile 2>&1
|
sed -E "s~>(\w|\W){10}~\\${CYAN}Receiving\\${ENDCOLOR} FROM ${src}~g" | \
|
||||||
|
xargs -0 printf 1>>$syncloopfile 2>&1
|
||||||
# last command execution exit code $?"
|
# last command execution exit code $?"
|
||||||
rsync_result=$?
|
rsync_result=$?
|
||||||
if [[ ${rsync_result} -ne 0 ]]; then
|
if [[ ${rsync_result} -ne 0 ]]; then
|
||||||
|
2
masync
2
masync
@ -190,7 +190,7 @@ loopsyncpath() {
|
|||||||
rm -f ${rsynclogfile}
|
rm -f ${rsynclogfile}
|
||||||
## starting loop on background and catch pid
|
## starting loop on background and catch pid
|
||||||
syncloopfile=$(format ${SYNCLOOPFILE} hash=$hash)
|
syncloopfile=$(format ${SYNCLOOPFILE} hash=$hash)
|
||||||
nohup syncloop.sh $hash $localpath $remotepath 1>~/syncloop_$hash.nohup 2>&1 &
|
nohup syncloop.sh $hash $localpath $remotepath 1>$syncloopfile 2>&1 &
|
||||||
mypid=$!
|
mypid=$!
|
||||||
when=$(date +%s)
|
when=$(date +%s)
|
||||||
## if line exists i must replace it with new pid
|
## if line exists i must replace it with new pid
|
||||||
|
16
syncloop.sh
16
syncloop.sh
@ -26,11 +26,17 @@ source ~/bin/.synccmd.sh
|
|||||||
source ~/bin/.colordef.sh
|
source ~/bin/.colordef.sh
|
||||||
tmpqueuefile=$(format ${TMPQUEUEFILE} hash=$1)
|
tmpqueuefile=$(format ${TMPQUEUEFILE} hash=$1)
|
||||||
tmpqueuedeletes=$(format ${TMPQUEUEDELETES} hash=$1)
|
tmpqueuedeletes=$(format ${TMPQUEUEDELETES} hash=$1)
|
||||||
|
syncloopfile=$(format ${SYNCLOOPFILE} hash=$1)
|
||||||
|
|
||||||
|
exec 3>&1 4>&2
|
||||||
|
trap 'exec 2>&4 1>&3' 0 1 2 3
|
||||||
|
exec 1>>$syncloopfile 2>&1
|
||||||
|
|
||||||
LOCALPATH_HASH=$1
|
LOCALPATH_HASH=$1
|
||||||
LOCALPATH=$2
|
LOCALPATH=$2
|
||||||
REMOTEPATH=$3
|
REMOTEPATH=$3
|
||||||
|
|
||||||
|
|
||||||
REMOTEHOST=$(echo "$REMOTEPATH" | cut -d : -f 1 | cut -d @ -f 2)
|
REMOTEHOST=$(echo "$REMOTEPATH" | cut -d : -f 1 | cut -d @ -f 2)
|
||||||
REMOTERELATIVEPATH=$(echo "$REMOTEPATH" | cut -d : -f 2)
|
REMOTERELATIVEPATH=$(echo "$REMOTEPATH" | cut -d : -f 2)
|
||||||
|
|
||||||
@ -64,7 +70,7 @@ synccycle() {
|
|||||||
if [ -f "$tmpqueuedeletes" ]; then
|
if [ -f "$tmpqueuedeletes" ]; then
|
||||||
ndeletes=$(wc -l < ${tmpqueuedeletes})
|
ndeletes=$(wc -l < ${tmpqueuedeletes})
|
||||||
while [ $ndeletes -gt 0 ]; do
|
while [ $ndeletes -gt 0 ]; do
|
||||||
echo -n -e "[Masync log - PUSH FILES TO DELETE] to remote: ${RED}$(head -n $ndeletes ${tmpqueuedeletes} | tr '\n', ' ')${ENDCOLOR}"
|
echo -n -e "syncloop delete at remote: ${RED}$(head -n $ndeletes ${tmpqueuedeletes} | tr '\n', ' ')${ENDCOLOR}"
|
||||||
ssh $REMOTEHOST "rm -rf $(head -n $ndeletes ${tmpqueuedeletes} | tr '\n', ' ')"
|
ssh $REMOTEHOST "rm -rf $(head -n $ndeletes ${tmpqueuedeletes} | tr '\n', ' ')"
|
||||||
echo -e " ${PURPLE}DONE${ENDCOLOR}"
|
echo -e " ${PURPLE}DONE${ENDCOLOR}"
|
||||||
# remove the first ndeletes lines
|
# remove the first ndeletes lines
|
||||||
@ -83,7 +89,7 @@ synccycle() {
|
|||||||
nqueue=$(wc -l < ${tmpqueuefile})
|
nqueue=$(wc -l < ${tmpqueuefile})
|
||||||
while [ $nqueue -gt 0 ]; do
|
while [ $nqueue -gt 0 ]; do
|
||||||
#echo "${tmpqueuefile} not empty consume ${nqueue} updates in queue"
|
#echo "${tmpqueuefile} not empty consume ${nqueue} updates in queue"
|
||||||
echo -n -e "[Masync log - PUSH FILES] to remote: ${GREEN}$(head -n ${nqueue} ${tmpqueuefile} | tr '\n', ' ')${ENDCOLOR}"
|
echo -n "syncloop START SYNC"
|
||||||
sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH
|
sync $LOCALPATH_HASH $LOCALPATH $REMOTEPATH
|
||||||
echo -e " ${PURPLE}DONE${ENDCOLOR}"
|
echo -e " ${PURPLE}DONE${ENDCOLOR}"
|
||||||
# remove the first nqueue lines from queue
|
# remove the first nqueue lines from queue
|
||||||
@ -102,7 +108,7 @@ synccycle() {
|
|||||||
elapsed="$(bc <<<"$now-$lastsynctime")"
|
elapsed="$(bc <<<"$now-$lastsynctime")"
|
||||||
## if elapsed is greater than maxpulllimit sync from remote with delete option
|
## if elapsed is greater than maxpulllimit sync from remote with delete option
|
||||||
if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then
|
if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then
|
||||||
echo -n "[Masync log - PULL LIMIT reached] $maxpulllimit seconds reached: sync from remote with --delete option..."
|
echo -n "syncloop $maxpulllimit seconds reached: sync from remote with --delete option..."
|
||||||
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
|
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
|
||||||
echo -e " ${PURPLE}DONE${ENDCOLOR}"
|
echo -e " ${PURPLE}DONE${ENDCOLOR}"
|
||||||
lastsynctime="$(date -u +%s.%N)"
|
lastsynctime="$(date -u +%s.%N)"
|
||||||
@ -124,7 +130,7 @@ synccycle &
|
|||||||
# exclude swp,swpx and 4913 files created by vim
|
# exclude swp,swpx and 4913 files created by vim
|
||||||
inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\.swx|4913|.txt~" $LOCALPATH | while read dir action file; do
|
inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\.swx|4913|.txt~" $LOCALPATH | while read dir action file; do
|
||||||
if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ] || [ $action = 'MOVED_FROM' ] || [ $action = 'MOVED_FROM,ISDIR' ]; then
|
if [ $action = 'DELETE' ] || [ $action = 'DELETE,ISDIR' ] || [ $action = 'MOVED_FROM' ] || [ $action = 'MOVED_FROM,ISDIR' ]; then
|
||||||
echo -e "[Masync log - ENQUEUE delete] $dir$file"
|
echo -e "syncloop - ENQUEUE delete $dir$file"
|
||||||
flock $lock_deletes
|
flock $lock_deletes
|
||||||
echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${tmpqueuedeletes} 1>/dev/null
|
echo $dir$file | sed -e "s~$LOCALPATH~$REMOTERELATIVEPATH~g" | tee -a ${tmpqueuedeletes} 1>/dev/null
|
||||||
flock -u $lock_deletes
|
flock -u $lock_deletes
|
||||||
@ -133,7 +139,7 @@ inotifywait -m -r -e create -e close_write -e move -e delete --exclude "\.swp|\.
|
|||||||
## add to queue only if not already in it
|
## add to queue only if not already in it
|
||||||
if [ $(grep -E ${file}$ ${tmpqueuefile} | wc -l) -lt 1 ]; then
|
if [ $(grep -E ${file}$ ${tmpqueuefile} | wc -l) -lt 1 ]; then
|
||||||
#echo "Add notify to queue: file '$file' in directory '$dir' for '$action'" | tee -a ${tmpqueuefile}
|
#echo "Add notify to queue: file '$file' in directory '$dir' for '$action'" | tee -a ${tmpqueuefile}
|
||||||
echo -e "[Masync log - ENQUEUE file] $dir$file"
|
echo -e "syncloop - ENQUEUE file $dir$file"
|
||||||
# AVOID TO USE TEE: SIMPLY append
|
# AVOID TO USE TEE: SIMPLY append
|
||||||
#echo ${dir}${file} | tee -a ${tmpqueuefile}
|
#echo ${dir}${file} | tee -a ${tmpqueuefile}
|
||||||
echo ${dir}${file} >> ${tmpqueuefile}
|
echo ${dir}${file} >> ${tmpqueuefile}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user