smbclient - check if 'cd' is sucessful?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting smbclient - check if 'cd' is sucessful?
# 8  
Old 08-21-2012
Quote:
Originally Posted by pamu
Give dir_name as path of the directory you want to check...

Code:
if [[ -d $dir_name ]] 
then 
#do what you want here..
echo "Pass"
fi

I did...same result/error-message :-(

Code:
	fileattr=`/opt/samba/bin/smbclient --authentication-file=$AUTH_FILE //$SMB_HOST/$SMB_SHARE 2> /dev/null 
	prompt off
	if [[ -d $SMB_DIR ]]
	then
            cd $SMB_DIR
	    put $LOC_FILE $SMB_FILE
	    dir /$SMB_DIR/$SMB_FILE
	fi

	exit
`

# 9  
Old 08-21-2012
It so weird that if command is not working there...

and i am doubtful about working of while...

still try this...

Code:
cd $dir_name
var=$(echo $?)
echo $var
while [ "$var" == 0 ]; do
echo "Pass" 
var=1;
done

Hope this should work for you..Smilie
This User Gave Thanks to pamu For This Post:
# 10  
Old 08-21-2012
Did this script ever work? AFAIK smbclient needs commands from stdin, so a "here document" might work. Anyhow, the shell is NOT reading those lines after the smbclient command, and thus no variable expansion nor an if evaluation should be expected. Have you tried to put the smb commands into a file and source it to smbclient?
I have to correct myself: some expansion may be done in (bash!) here documents:
Quote:
Here Documents
This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.

The format of here-documents is:

<<[-]word
here-document
delimiter

No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion. In the latter case, the character sequence \<newline> is ignored, and \ must be used to quote the characters \, $, and `.

Last edited by RudiC; 08-21-2012 at 10:07 AM.. Reason: here document correction
This User Gave Thanks to RudiC For This Post:
# 11  
Old 08-21-2012
Please always post what Operating System and version you are running and what Shell you use. There is so much variation.
Please also post the Operating System and version of the remote (Microsoft?) server.



(Deleted code suggestion because I fell into the same trap as other posters. The Directory concerned is on a remote server and not visible to basic unix commands.)


Afterthought.
Could do this in two runs of smbclient.
1) Just issue a cd and check what happens
2) If successful, run the full script (obviously repeating the cd but knowing that it will work).

Last edited by methyl; 08-21-2012 at 06:44 PM.. Reason: delete code suggestion; then add afterthought
This User Gave Thanks to methyl For This Post:
# 12  
Old 08-22-2012
Quote:
Originally Posted by methyl
.
.
.
(Deleted code suggestion because I fell into the same trap as other posters. The Directory concerned is on a remote server and not visible to basic unix commands.)
This is where my smbmount proposal comes into play. You smbmount the remote resource and - voila - all your unix commands will work.

Quote:
Afterthought.
Could do this in two runs of smbclient.
1) Just issue a cd and check what happens
2) If successful, run the full script (obviously repeating the cd but knowing that it will work).
This is what I first thought of, but I'm not sure the result of cd will be conveyed correctly. And, it's quite clumsy, ain't it? He/she still will need a mechanism to expand the varables with his filenames etc.

Update: exit code will NOT reflect CD failure. You will have to write an error file and analyse it.

Last edited by RudiC; 08-22-2012 at 02:50 AM.. Reason: cd error analysis
This User Gave Thanks to RudiC For This Post:
# 13  
Old 08-22-2012
Thanks all of you for your help and hints. I think I'll give smbmount a try Smilie
# 14  
Old 08-22-2012
OK, pls report back your results.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Aria2c will not exit after sucessful download

I am using the below aria2c command to call an API that downloads a file to a directory. Though the process completes and I get "download complete"... aria2c does not exit to the command line, I have to hit enter to get the command line. I am not sure what is wrong. Am I missing something in... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Linux

Error on smbclient login on Red Hat

I have the smbclient installed and I am able to see information from the '-L' option. But when I attempt to login I'm getting the "NT_STATUS_BAD_NETWORK_NAME". I was hoping for help, because I'm not sure what is supposed to go into the smb.conf file. My goal is to transfer files from my Linux... (2 Replies)
Discussion started by: islanderman
2 Replies

3. UNIX for Dummies Questions & Answers

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) smbclient '{servicename}' -A ~/.smbclientauth -c 'mkdir \test_folder"' smbclient '{servicename}' -A ~/.smbclientauth -c 'cd "; lcd ";... (4 Replies)
Discussion started by: gary2410
4 Replies

4. Shell Programming and Scripting

Shell Script - If and smbclient (ftp)...help

Hi, So I am writting a script to copy files from Linux to windows using smbclient, I have done this a fair amount of times now. Unfortunately this time I am using a simply if statement to determine if the file exists before beginning the smbclient section.....however if I tab the smbclient... (4 Replies)
Discussion started by: mcclunyboy
4 Replies

5. Shell Programming and Scripting

Issue on smbclient

Hi All, I've been facing on this issue. From SunOS to Windows /usr/local/samba/bin/smbclient \\IP\<source dir> -D $TARGET_DIR -U dir1/$WINDOWS_USER%$WINDOWS_PWD -c "put $SOURCE_FILE $TAR GET_FILE;exit" This command in my shell script work fine but the file saved on windows environment... (3 Replies)
Discussion started by: gio123bgg
3 Replies

6. 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

7. 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

8. UNIX for Dummies Questions & Answers

Smbclient on Unix

The directory on windows server is renamed and I need to change the directory location on smbclient on unix. How do i do that, please advice. (2 Replies)
Discussion started by: welldone
2 Replies

9. UNIX for Dummies Questions & Answers

smbclient print while preserving windows printer settings?

I have successfully gotten AIX to print to a windows shared printer with this command: smbclient -U user%password -W domain -c "print file.ext" the only problem is: I have this print queue set up on the Windows side to overlay an image to all pages. When printing from samba, the overlay... (2 Replies)
Discussion started by: raidzero
2 Replies

10. UNIX for Advanced & Expert Users

Incomplete reading and transferring zip file via SAMBA smbclient

Hello, Anyone out there can help on this problem? I have a zip file about 34MB containing a file in EBCDIC and is resided on a Windows 2000 server. This zip file is retrieved and read from a UNIX server via SAMBA "SMBCLIENT" (by default the file is transferred via command bin) and issued... (2 Replies)
Discussion started by: eddie Law
2 Replies
Login or Register to Ask a Question