- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script to copy file from several directories
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 07:04 AM
тАО04-05-2011 07:04 AM
Hi All
I need to scp files from several subdirecories within the same directory to another server.
Pls can you help?
F.R.
Solved! Go to Solution.
- Tags:
- scp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 07:37 AM
тАО04-05-2011 07:37 AM
Re: script to copy file from several directories
What are you stuck with?
Setup public ssh keys between the servers in question. Then write whatever 'scp' command you need! For example:
# scp -p mydir/mysubdir1/myfile1 thathost:/itsdir/itsfile
Search or Google ssh and public keys if you don't know how to set that up. The manpages for 'scp' would also help you.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 09:25 AM
тАО04-05-2011 09:25 AM
Re: script to copy file from several directories
it is that simple
if the destination for all these files are different too, that that's another story and each different destination will need a separate scp command.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 11:25 AM
тАО04-05-2011 11:25 AM
Re: script to copy file from several directories
Hi
The problem is that I need to scp all february files from 318 directories to just one destination. But the source are 318 subdirectories within one directory . I know how to select the february files. what I dont want is to create 318 scripts and run them.
F.R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 11:40 AM
тАО04-05-2011 11:40 AM
Re: script to copy file from several directories
/logs/2011/Jan
/logs/2011/Feb
/logs/2011/Mar
/logs/2011/Apr
and each of these have 300+ subdirectories under each of them. Right ? If so, let's take Feb subdirectory as an example since you mentioned it.
cd /logs/2011/Feb
scp -rp * remote_server:/var/logs/Feb
make sure on the remote server, directory /var/logs/Feb exists or if you want scp to create it, use this syntax:
cd /logs/2011
scp -rp Feb remote_server:/var/logs
again make sure the /var/log target directory exists on the remote server.
switch -r means copy subdirectories recursively and -p means preserve modification times, access times, and modes from the original file.
Hope this helps. More details you provide instead of rounding up your question, better answers you get around here. Just remember that next time you are about to ask a question. We are not mind readers unfortunately
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 12:12 PM
тАО04-05-2011 12:12 PM
Re: script to copy file from several directories
It might be fortunate. Imagine what we might
see if we could. Gahhh.
> But my assumption is, [...]
We should not need to assume anything.
> [...] another server.
For example, we should not need to assume
what "another server" is, or its OS.
> I need to scp files [...]
I doubt it.
> [...] 318 directories [...]
Is there some reason not to use, say, "tar"
to create one archive containing all these
files, and then copy _that_ to "another
server"?
Perhaps you should start by trying to decide
(and describe) exactly _what_ it is that you
need to do, and _then_ worry about exactly
_how_ you "need" to do it.
Or, you could just continue to waste
everyone's time the same way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 06:21 PM
тАО04-05-2011 06:21 PM
Re: script to copy file from several directories
You don't need 318 scripts but you may need 318 lines in your script.
Or if the target is in one directory, you can list 318 source files, like Mel mentioned:
scp \
file1 \
[...] \
host2:target-directory
If you have a script that can select those files, you can replace the above by:
scp $(selection-script.sh) host2:target-directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 10:09 PM
тАО04-05-2011 10:09 PM
Re: script to copy file from several directories
Hi
let me explain again:
lets say I have directory Europe, inside this directory I have 318 subdirectories all under Europe. Now under this 318 subdirectories are thousand of files, all created in differente months, days etc. So what I want is to scp only the files created in february of this 318 subdirectories to a single destination on another server. So I have multiple sources (318) but only one target.
F.R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2011 10:58 PM
тАО04-05-2011 10:58 PM
Re: script to copy file from several directories
the script I use for one directory is as follows:
for JOB in `ls -lrt | awk '{if ($6 == "Feb" && $8 != 2010)print $9}'`
do
scp -p /global/xnode/mcel/tap_out/
F.R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 03:21 AM
тАО04-06-2011 03:21 AM
Re: script to copy file from several directories
First, I would create two marker files. file1 should have a timestamp of february 1st, file2 february 28.
# touch -t 201102010000 file1
# touch -t 201102282359 file2
With these two, the following find command will result in all the files you need to copy:
# find /Europe -newer file1 -a ! -newer file2 -print
With this, you can generate a file list, tar it and scp it. I'm not sure if you want to copy these with full path or not, but you can achieve both with tar.
you can use the exec option of find:
# find /Europe -newer file1 -a ! -newer file2 -exec tar cvf {} \;
or you can use pax if you prefer it:
# find /Europe -newer file1 -a ! -newer file2 | pax -v -w -f /tmp/myarchive
Regards,
Viktor
Unix operates with beer.