Reputation: 166
I want to put a whole directory that contains pdf files on another server with a smbclientscript. My script:
#Set variable for reports
variable=`ls | grep pdf`
smbclient -U "server\user"%pw //some/direc/tory/bla/bla << Commands
cd to/another/dir
put $variable
exit
Commands
It actually works, but the problem ist that it can only copy the first file that is listet bei ls | grep pdf. For the other Files the shell responds with file:command not found.
Upvotes: 0
Views: 2748
Reputation: 166
I got the solution be myself:
cd /directory/with/files/to/copy
#Set Variable
reports=$(ls *)
for i in $reports ; do
smbclient -U "srv\User"%pws //some/dir/bla/bla/bla << Commands
cd another/dir/etc
put $i
exit
Commands
done
Thanks!
Upvotes: 0
Reputation: 106
In bash
variable=`ls |grep pdf`
will get a string variable with STDOUT, not an array. It's no what you want.
Maybe xargs
will help you. You can do as follows, but not an elegant solution I think.
ls | grep '.pdf$' |xargs -I{} smbclient -U "server\user"%pw //some/direc/tory/bla/bla -D 'to/another/dir' -c "{}"
Upvotes: 1