SSH -rsync
Hi Folks,
I encountered a strange problem. There is a video encoder that constantly records files, and I created this syncroniser script. If I --remove-source-files parameter to rsync it senses that a file is beeing written by another process, and skips that file. I tested it on my laptop and it really skips it, but not always. On the server side some files are truncated to 828 bytes. Now I user it without that option, but I would really like to remove the files after sync: Code:
#!/bin/sh Code:
find $SRC -type f -exec sh -c 'if ! lsof `readlink -f {}` > /dev/null; then echo `basename {}`; fi' \; | tr '\n' '\0' | rsync -avme "ssh -i $KEY -p $REMOTE_PORT" $SRC $REMOTE_USER@$REMOTE_IP:$DST |
There's a lot which appears undefined in the script as presented. The variables $REMOTE_PORT, $REMOTE_USER, $REMOTE_IP, and $DST seem undefined. The variable $MAC seems unused but if you are going to fetch it using the formula which you have given, then it can all be done in AWK:
Code:
MAC=$(ip a | awk '/link\/ether/ { gsub(":", "-", $2); print $2; exit; };') |
Do you mean you want to copy a file which is actually being written? That won't work, you cannot make it work. You need to skip that file. Next time you can copy/move it when it's saved and ready.
Instead of Code:
echo `basename {}` Code:
basename {} |
This is shell checked :-)
Code:
set -x |
Hi Folks,
Do you have idea why I cannot use this script with systemD anymore? It was running seamlessly before I added the red line. Code:
#!/bin/sh |
Code:
find $SRC -name *.mkv -mmin +1 -exec mv "{}" "$EXPORTS" \; |
If your video encoder runs on the same linux machine, why don't you hook you script to it - via inotifywait, if there are no more straightforward means. And if it is a separate device which exposes its storage to linux as memory card, lsof trick won't work as it cannot see files opened there. As for that 'find $SRC -name *.mkv...' line, you have to enquote the file mask, otherwise it will be expanded prematurely.
|
All times are GMT -5. The time now is 09:36 PM. |