Search code examples
linuxshellsamba

smbclient script putting several files with variable


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.


Solution

  • 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!