Using command line variables in smbclient


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using command line variables in smbclient
# 1  
Old 06-24-2013
Code Using command line variables in smbclient

Hi All,

Have written a couple of lines to move the contents of a folder from a unix box to a windows location using smbclient (below)

Code:
 
 
smbclient '{servicename}' -A ~/.smbclientauth -c 'mkdir [network location]\test_folder"'
smbclient '{servicename}' -A ~/.smbclientauth -c 'cd [unix location]"; lcd [unix location]"; prompt;recurse; mput *; exit;'

Running the code on the command line ($ loadsmv.sh) works fine when the name of the folder is already in the code, however, I would like to try and use a command line variable to name the folder.

So the code would be run as ($ loadsmv.sh data_trans) which would then create a folder in the windows directory and read from the folder with the same name on the unix box.
I have tried various combinations of variable names and formats without much luck and am struggling trying to find the answer on google.
Any suggestions please?

Thanks in advance Smilie
# 2  
Old 06-24-2013
Assuming you used single quotes in your shellscript as you did in the example above. Single quotes prevent variable expansion, meaning, that "$WHATEVER" goes literally into the command.

Replacing single quotes with double quotes might solve your problem.

By the way, your example above has unbalanced double quotes.
# 3  
Old 06-24-2013
Yeah, that was me with the unbalanced quotes!

So the line;

Code:
smbclient '{servicename}' -A ~/.smbclientauth -c 'mkdir [network location]\test_folder'

would become

Code:
smbclient '{servicename}' -A ~/.smbclientauth -c 'mkdir [network location]\"$WHATEVER"'

and the second line would become

Code:
smbclient '{servicename}' -A ~/.smbclientauth -c 'cd [unix location]/"${WHATEVER}"; lcd [unix location]/"${WHATEVER}"; prompt;recurse; mput *; exit;'

So the command line would look like ($ loadsmv.sh FOLDER) and FOLDER would be created in windows and FOLDER would be read on the unix box?

Am learning this on the "fly", so thanks for any help
# 4  
Old 06-24-2013
No, the variable must not be enclosed in single quotes. Try

Code:
smbclient '{servicename}' -A ~/.smbclientauth -c 'mkdir [network location]\\'"$WHATEVER"

instead. Notice, that the single quotes are closed before the variable. And the backslash has to be doubled, so that it stands for itself and does not escape the following single quote.
This User Gave Thanks to hergp For This Post:
# 5  
Old 06-24-2013
Yeah, have it and it works!
Second line was a complete b*tch though Smilie

Thank you very much for your help
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read line by line and calculate the co-presence of variables

Hey guyz, I have a table which shows the presence or absence of my variables (A,B,C,...) in my observations (1,2,3,...) * A B C ... 1 1 0 1 2 1 1 0 3 1 0 0 ... I want to calculate the co-presence of my variables. to have a table shows the pairwise presence of the variables (have... (1 Reply)
Discussion started by: @man
1 Replies

2. UNIX for Advanced & Expert Users

smbclient & dd

you know I am told to get an image of the whole ubuntu system on my server shared folder. If you have used dd before to get an image of the occupied space on the system please lemme know bout your command. (I preferably want dd to only get an image of the occupied file system not the free space)... (11 Replies)
Discussion started by: dr_mabuse
11 Replies

3. Shell Programming and Scripting

linux shell script to take variables from two different files line by line

Friends I need to have a shell script which will feed variables from two different files line-by-line. For example, I have two files - permission and file_name. Contents of permission is - 644 755 .... contents of file_name /file1 /file2 ..... Now I want 644 permission will be... (4 Replies)
Discussion started by: atanubanerji
4 Replies

4. Shell Programming and Scripting

using sed command to display contents where line numbers are stored in variables

if i want to display the contents of a file between say line number 3 and 10 then i use the following command sed -n '3,10p' filename if this 3 was contained in x and 10 was contained in y then how wud this command modified? sed -n '$x,$yp' filename does not work..please advise (2 Replies)
Discussion started by: arindamlive
2 Replies

5. Shell Programming and Scripting

[bash] command line substitution with environmental variables

Hi, I'm using an array that contains compiler FLAGS that need to be executed either before ./configure or after the main 'make' command. example of array containing compiler flags. ------------------------------------------------- FLAGS="CFLAGS=\"-arch x86_64 -g -Os -pipe... (7 Replies)
Discussion started by: ASGR
7 Replies

6. Shell Programming and Scripting

Using the smbclient

Hi, I am trying to use smbclient to send message to a windows machine.It is showing "connection failed message" . After googled I came to know about "smbfind" which will give me the nodes in my network. In that list the machine name was not present where I was trying to send the message. ... (1 Reply)
Discussion started by: forstudy3
1 Replies

7. Solaris

"smbclient" command not working

I've installed Samba on my Solaris 10 (SPARC) server # pkginfo |grep samba system SUNWsmbac samba - A Windows SMB/CIFS fileserver for UNIX (client) system SUNWsmbar samba - A Windows SMB/CIFS fileserver for UNIX (Root) system ... (1 Reply)
Discussion started by: soliberus
1 Replies

8. Shell Programming and Scripting

Can i use Variables in sed command in line numbers

I wish to give line number from one point to another in sed command like this sed -n 1,1000000p file1.txt >file2.txt but variable line number $x,$x+100000 can i give it cos i tried and it was giving an error any suggestions?/ Thx in advance AC (2 Replies)
Discussion started by: bezudar
2 Replies

9. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

10. UNIX for Dummies Questions & Answers

How do you take in variables/parameters from the command line?

I need to take in two parameters from the command line...help! (1 Reply)
Discussion started by: avisram
1 Replies
Login or Register to Ask a Question