Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
set -x
MAC=$(ip a | grep ether | head -1 | awk '{print $2}' | sed 's/:/-/g')
CONFIG="/usr/bin/syncroniser.cfg"
KEY="/usr/bin/dropbear_rsa_host_key"
SRC="/media/sdmmc/mmcblk0p1/RECORD/"
DST="$MAC"
FREQ=60
while true
do
if test -f "$CONFIG"; then
. "$CONFIG"
fi
rsync -avme "ssh -i $KEY -p $REMOTE_PORT" $SRC $REMOTE_USER@$REMOTE_IP:$DST
sleep $FREQ
done
I was trying to pipe to rsync with find and xargs, but it still did that file truncation on the file beeing written.
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:
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 {}`
you can simply write
Code:
basename {}
Also would be nice to use shellcheck to validate your script.
What exactly isn't working correctly? What sticks out is that by default find is recursive. I have not tried testing your code but try adding -maxdepth 0 and you need quotes around *.mkv
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.