Question

I am running the following commands:

FILES=`/usr/bin/find /u01/app/dw/admin/dgwspool -type f -daystart -mmin -1621`;
/usr/bin/smbclient //techshare.something.com/Depts/ -I 129.0.0.1 -D ITIS/deptshare/degreeworks/Test -U domain\\user%password -c "prompt off; mput $FILES"

I've tested this, the $FILES variable is filled with a space-delimited list of filenames. The smblclient command connects to the windows share as I would hope, and if I put in a hard-coded filename it will copy the file (or files) to the share.

What seems to be happening is that the $FILES variable is not expanded, or is being evaluated in some internal smbclient scope.

How can I get this to work?

Was it helpful?

Solution

My psychic powers tells me that you tested this with echo $FILES, which printed all the files on one line, leading you to believe that $FILES was spaces separated. This is not the case.

With echo $FILES, the shell word splits the variable on spaces and line feeds into multiple arguments, which echo then joins with spaces. If you use echo "$FILES", you'll see that it is in fact line feed separated.

The quick fix is to print the file names space separated (requires GNU find or other find with -printf). As per comment, it also omits the search path:

FILES=`/usr/bin/find /u01/app/dw/admin/dgwspool -type f -daystart -mmin -1621 -printf '%P '`;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top