LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2010, 10:28 PM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
smbmount - find and copy


I have the following code and would like to copy all the found files within the if then loop.

Code:
smbmount //$IP/C$ /mnt/win sec=ntlmv2i -o user=USERNAME,pass=PASSWORD,ro
        if [ $? == 0 ]; then
          cd /mnt/win/$WINFOLDER
          find . -name '*.pl' >> $DESTFOLDER/$IP/found.txt
          cd /mnt
        fi
smbumount /mnt/win/
I can pipe it to a file then run a smbclient get on the file listing but there must be a better way to do this.

Thanks & Regards
 
Old 11-20-2010, 12:39 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
You don't say where you want to copy the matching files. So you'll need to modify the commands as necessary:

You can use the -exec option with find. Something like:
Code:
find . -name '*.pl' -exec cp {} <destination_path> \;
That command will invoke cp once for every matching file found. If you don't want that overhead, you could do something like this:

Code:
find . -name '*.pl' | xargs cp {} <destination_path>
In this case, you execute cp only once, but it forces your script to copy all the matching files to a single directory. Also keep in mind that if you have a LOT of matching files, the command may exceed the maximum length--causing the cp command to fail.
 
1 members found this post helpful.
Old 11-20-2010, 12:45 AM   #3
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Thanks for the response.

I would like to copy the files to my linux home directory (where I am running the script from) and put the 'found' files into seperate directory's named $IP something like this:

Quote:
find . -name '*.pl' -exec cp {} $DESTFOLDER/$IP \; >> $DESTFOLDER/$IP/found.txt
I dot not expect too many hits, max about 10 for what I am trying to achieve so the cp would work.

Thanks & Regards,

Last edited by hattori.hanzo; 11-20-2010 at 12:55 AM.
 
Old 11-20-2010, 01:04 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Code:
find . -name '*.pl' -exec cp {} $DESTFOLDER/$IP \; >> $DESTFOLDER/$IP/found.txt
That won't do what you're hoping it will do.

When you use the -exec option with the find command, the normal output from find is suppressed. The output is replaced by the output of the executed command. So your found.txt file will be empty.

You can fix that with another option to find:
Code:
find . -name '*.pl' -print -exec cp {} $DESTFOLDER/$IP \; >> $DESTFOLDER/$IP/found.txt
 
1 members found this post helpful.
Old 11-20-2010, 06:52 AM   #5
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Thanks. The -print -exec was exactly what I needed. I learn something new whenever I visit this place.

Thanks & Regards,

Last edited by hattori.hanzo; 11-20-2010 at 07:21 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Find and copy in the same directory greenpoise Linux - Newbie 20 09-01-2010 01:45 PM
Find and Copy command comdined together manjeshjk Linux - Newbie 8 02-26-2010 05:27 AM
mount.cifs will not allow me to copy directories, smbmount will DiBosco Linux - Networking 2 07-05-2009 10:06 AM
can't find zm script file to copy. Buddhike G Linux - Software 1 10-08-2007 05:17 PM
copy with find ovince Programming 1 03-21-2007 10:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration