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) and this MAY work from terminal but not within a bash script.<div>
<br></div><div>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".</div><div><br></div><div>Here is my bash script with an example of what DOES work and what does not.<br>
<div><br></div><div>---</div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">#! /bin/bash</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
DATE=$(date +"%Y%m%d")</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">FILENAME='"ABC logname '$DATE'.log"'</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
DIRECTORY='ABC\"ABC Logs"\Logs'</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
#EXAMPLE 1 - this DOES work</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">smbclient -A authfile //windows_machine_IP<a href="http://192.168.4.9/C$" target="_blank" style="color:rgb(17,85,204)">/C</a><a href="http://192.168.4.9/C$" target="_blank" style="color:rgb(17,85,204)">$</a> -c 'cd \\ABC\"ABC Logs"\Logs; get "ABC Logs 20121231.log" abclog.txt'</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<div>#EXAMPLE 2 - this does NOT work</div><div>smbclient -A authfile //windows_machine_IP<a href="http://192.168.4.9/C$" target="_blank" style="color:rgb(17,85,204)">/C$</a> -c 'cd \$DIRECTORY; get $FILENAME abclog.txt'</div>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">---</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">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 ?</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Thanks,</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Lux</div><div>
<br></div><div><br></div>
</div></div>