If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Secure copy only a certain type of files with out knowing the name of subdirectory

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-08, 09:52
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Secure copy only a certain type of files with out knowing the name of subdirectory

Hello Gurus,

I am kind of new to shell scripting , is there any way we can secure copy only certain type of files without knowing the name of the sub directory

ex: i have a directory called dir1 which changes its name based on the date and under that we have another sub directory which can ab , bc or cd and in those directories i i have pdf files which in need to get from source to destination.

Thank you in advance
Reply With Quote
  #2 (permalink)  
Old 04-17-08, 11:12
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You don't mean something like this?
Code:
scp user@host:/some/dir/*/*/*.pdf ...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 04-17-08, 11:24
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Quote:
Originally Posted by stolze
You don't mean something like this?
Code:
scp user@host:/some/dir/*/*/*.pdf ...

Exactly That is how i need
Reply With Quote
  #4 (permalink)  
Old 04-17-08, 11:28
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,452
Code:
scp user@host:/some/dir/*/*/*.pdf ...
This may not work if the number of files is sufficiently large. I'd go with
Code:
find /some/dir -name "*.pdf" -exec scp '{}' user@host:/target/dir/ \;
Reply With Quote
  #5 (permalink)  
Old 04-17-08, 11:36
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Quote:
Originally Posted by n_i
Code:
scp user@host:/some/dir/*/*/*.pdf ...
This may not work if the number of files is sufficiently large. I'd go with
Code:
find /some/dir -name "*.pdf" -exec scp '{}' user@host:/target/dir/ \;

Hello n_i,
I need to copy from a remote site , will this work
Reply With Quote
  #6 (permalink)  
Old 04-17-08, 13:16
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Yes, if you don't do a pull from the remote host but rather a push. For that, you use the "find ..." as command for ssh.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 04-17-08, 15:48
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Quote:
Originally Posted by stolze
Yes, if you don't do a pull from the remote host but rather a push. For that, you use the "find ..." as command for ssh.
Thank you guys, really appreciate your help
Reply With Quote
  #8 (permalink)  
Old 04-18-08, 11:40
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Quote:
Originally Posted by sumanchal
Thank you guys, really appreciate your help
need one more help, when you do ssh, how are we going to put the find and scp part.

Thanks in advance
Reply With Quote
  #9 (permalink)  
Old 04-18-08, 13:07
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Another idea is to use ssh to get a list of files (via a find at the remote system), then scp to get those files:
Code:
for f in `ssh user@host "find /some/dir/ -name "*.pdf"`; do
    scp user@host:$f /some/local/dir
done
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #10 (permalink)  
Old 04-18-08, 13:36
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Quote:
Originally Posted by stolze
Another idea is to use ssh to get a list of files (via a find at the remote system), then scp to get those files:
Code:
for f in `ssh user@host "find /some/dir/ -name "*.pdf"`; do
    scp user@host:$f /some/local/dir
done
hello stolze,
i am getting this error, command substitution: line 1: unexpected EOF while looking for matching `"'
Reply With Quote
  #11 (permalink)  
Old 04-18-08, 14:04
sumanchal sumanchal is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
Quote:
Originally Posted by sumanchal
hello stolze,
i am getting this error, command substitution: line 1: unexpected EOF while looking for matching `"'

Hello Stolze, Thank you very very much, really appreciate your help, double quote was missing, is there any way that i can give the password only once when i connect using ssh, it is asking every time bcoz of the loop
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On