Find specific files and move them with smbclient

北战南征 提交于 2021-02-08 10:12:46

问题


$ 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 *.gz under 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 find works, it's just the last bit that does not. Any ideas?


回答1:


You can use xargs to create parameters from input stream

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:

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


来源:https://stackoverflow.com/questions/16235877/find-specific-files-and-move-them-with-smbclient

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!