Find the answer to your Linux question:
Results 1 to 3 of 3
I have googled this subject extensively and found several examples where authors have advised that using variables IS possible in a smbclient command string (using -c). Although this MAY work ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    20

    SOLVED smbclient in bash script


    I have googled this subject extensively and found several examples where authors have advised that using variables IS possible in a smbclient command string (using -c). Although this MAY work from terminal it is not working for me within a bash script.

    Here is what I am trying to do: retrieve a log file from a windows machine on my LAN and copy the contents to a file on my linux box called "abclog.txt".

    Here is my bash script with an example of what DOES work and what does not.

    Code:
    #! /bin/bash
    DATE=$(date +"%Y%m%d")
    FILENAME='"ABC logname '$DATE'.log"'
    DIRECTORY='ABC\"ABC Logs"\Logs'
    
    #EXAMPLE 1 - this DOES work
    smbclient -A authfile //windows_machine_IP/C$ -c 'cd \\ABC\"ABC Logs"\Logs; get "ABC Logs 20121231.log" abclog.txt'
    
    #EXAMPLE 2 - this does NOT work
    smbclient -A authfile //windows_machine_IP/C$ -c 'cd \$DIRECTORY; get $FILENAME abclog.txt'
    The problem in example 2 is that smbclient simply looks for something called $DIRECTORY instead of interpreting the variable as defined. Is there a way to overcome this or perhaps a suggestion for a different approach ?

    Thanks for suggestions.
    Lux11
    Last edited by lux11; 01-02-2013 at 11:26 AM. Reason: SOLVED

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    211
    expansion doesn't happen between single quotes.
    you'll also need to protect \
    Code:
    smbclient -A authfile //windows_machine_IP/C$ -c "cd \\$DIRECTORY; get $FILENAME abclog.txt"

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    20
    Thanks, that was simple enough. Double quotes did the trick.
    Lux11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •