bash 查找特定文件并使用 smbclient 移动它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16235877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find specific files and move them with smbclient
提问by user2323684
$ find /opt/backup/test -name "*.gz" -exec smbclient -A \
/opt/backup/smbclient_authentication.txt //1.1.1.1/test -c put '{}' \;
There are multiple directories and other files then *.gzunder the dir and I want to move the files found with find with smbclient. Of course, this does not work, since I am missing the last bit. Connection to the share works, and findworks, it's just the last bit that does not. Any ideas?
目录*.gz下有多个目录和其他文件,我想使用 smbclient 移动 find 找到的文件。当然,这不起作用,因为我错过了最后一点。与共享的连接有效,并且find有效,只是最后一点无效。有任何想法吗?
回答by rzymek
You can use xargsto create parameters from input stream
您可以使用xargs从输入流创建参数
xargs find /opt/backup/test -name "*.gz" \
| smbclient -A /opt/backup/smbclient_auth.txt //1.1.1.1/test -c put
If I understand correctly you want to move the files locally besides transferring the via smb. You could:
如果我理解正确,除了通过 smb 传输之外,您还想在本地移动文件。你可以:
set -e #<- abort on error
for f in `find -name '*.gz' -or -name '*.zip'`; do
smbclient -A /opt/backup/smbclient_auth.txt //1.1.1.1/test -c put "$f"
mv "$f" ./transfered/
done

