- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Help perl scp script
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
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
тАО01-08-2008 01:35 PM
тАО01-08-2008 01:35 PM
I create a perl script that tar all files in directory.
Dev Server:
/dir/dir1/upload
/dir/dir2/upload
/dir/dir3/upload
No problem creating tar file in all directory above.
I want to scp the tar file from /dir/dir/upload
to PROD SRV. /dir/dir1, etc
my @upload_dir = ('/dir/dir1/upload',
'/dir/dir2/upload'
);
my @upload_server = ('prod_srv');
foreach my $dir (@upload_dir)
{
chdir ($dir);
system("tar cvf upload.tar *");
}
I appreciate all help.
JC
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 07:19 PM
тАО01-08-2008 07:19 PM
Re: Help perl scp script
script could do the job?
> system("tar cvf upload.tar *");
I'd use "tar cvf upload.tar .". For the
reason, see, for example:
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1191368
If you insist on using perl, and you do the
"tar" using system(), then why not use
system() again to do the scp operation? If
you use a simple shell script, why not just
put the scp command into it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 07:45 PM
тАО01-08-2008 07:45 PM
Re: Help perl scp script
Shell or perl
I want to scp tar file from
SERVER_A SERVER_B
/abc/dir1/upload /abc/dir1
/efg/dir2/upload /efg/dir2
/hij/dir3/upload /hij/dir3
/xzy/dir4/upload /xyz/dir4
JC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 07:52 PM
тАО01-08-2008 07:52 PM
Re: Help perl scp script
Ok. Go ahead. "man scp"? "scp -h"?
Do you have ssh working between these two
systems?
Is the problem how to put an scp command
into a script, or how to make an scp command
work, or what?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 06:58 AM
тАО01-09-2008 06:58 AM
Re: Help perl scp script
OK, lets start from the top.
I know how to scp a file from severA to severB
I need help in creating a script to scp tar files from
SERVER_A
/abc/dir1/XYZ/upload/upload.tar
/efg/dir2/DIR2/upload/upload.tar
/hij/dir3/ABC/upload/upload.tar
/xzy/dir4/upload/upload.tar
etc..
etc..
etc..
etc..
SERVER_B
/abc/dir1/XYZ
/efg/dir2/DIR2
/hij/dir3/ABC
/xyz/dir4
etc...
etc.
SERVER_C
/abc/dir1/XYZ
/efg/dir2/DIR2
/hij/dir3/ABC
/xyz/dir4
etc...
etc.
SERVER_A
scp /abc/dir1/XYZ/upload/upload.tar SERVER_B:/abc/dir1/XYZ
SERVER_A
scp /abc/dir1/XYZ/upload/upload.tar SERVER_C:/abc/dir1/XYZ
NOTE: That upload directory is just a holding area on SERVER_A I do not have a /abc/dir1/XYZ/upload/ on SERVER_B and SERVER_C
JC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 08:02 AM
тАО01-09-2008 08:02 AM
Re: Help perl scp script
You will need to copy your public ssh key to allow passwordless login to server_a and server_b.
Then after you created the tarball, test if the directory structure exists on the destination server. If not create it, otherwise just copy the file to the destination directory:
destdir="/abc/dir1/XYZ"
for i in a b; do
ssh server_$i test -d $destdir
if [ $? -ne 0 ]; then
ssh server_${i} mkdir -p $destdir
scp
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 12:29 PM
тАО01-09-2008 12:29 PM
Re: Help perl scp script
Thanks for the reply.
Following are my directory structure.
SERVER_A Example:
/usr/bin/test/upload
/etc/bin/home/upload
/sbin/home/help/upload
/var/sbin/home/bin/upload
..
..
/directory/ten/upload
In my perl script I loop/cd to /upload dir and tar all files in the directory, creating upload.tar file.
NEXT
After the upload.tar file is created on SERVER_A in /sbin/home/help/upload/upload.tar
I wan't scp the upload.tar file to SERVER_B and SERVER_C
scp /sbin/home/help/upload/upload.tar SERVER_B:/sbin/home/help
scp /sbin/home/help/upload/upload.tar SERVER_C:/sbin/home/help
THEN
create upload.tar file on SERVER_A in directory /var/sbin/home/bin/upload/upload.tar
scp /var/sbin/home/bin/upload/upload.tar SERVER_B:/var/sbin/home/bin/
scp /var/sbin/home/bin/upload/upload.tar SERVER_C:/var/sbin/home/bin/
etc,
etc,
-JC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2008 03:10 AM
тАО01-10-2008 03:10 AM
Re: Help perl scp script
by directly piping into ssh.
Here is a code snippet of one way how this could be done.
This requires a previously created and distributed RSA key (i.e. the arg to -i).
Please, adapt to your users, hosts, file paths etc.
my $ruser = 'someone';
my $rhost = '123.123.123.123';
my $ldir = '/etc';
my $rdir = '/var/tmp/etc.bak';
my $rsa_key = "$ENV{HOME}/.ssh/id_rsa";
my $pid = open PSSH, '|-';
die "cannot open pipe\n" unless defined $pid;
if ($pid) {
chdir $ldir;
select((select(PSSH), $|=1)[0]);
print PSSH qx(/bin/tar cf - .);
} else {
exec qw(/usr/bin/ssh -o BatchMode=yes -q -C -T -i),
$rsa_key, "$ruser\@$rhost",
"mkdir -p $rdir && cd $rdir && tar xf -";
}
close PSSH;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2008 10:18 AM
тАО01-10-2008 10:18 AM
Solution#!/usr/bin/perl
use strict;
my $upload="upload";
my @servers=( "10.10.10.10", "20.20.20.20");
my @dirs=("/usr/bin/test/","/etc/bin/home/","/sbin/home/help/","/var/sbin/home/bin/");
for my $dir (@dirs) {
print "Creating tar for $dir.\n";
my $localdir=$dir.$upload;
mkdir $localdir unless -d $localdir;
chdir $localdir;
system "tar cvf upload.tar ./*";
for my $server (@servers) {
print "Copying the tarball for $dir to $server.\n";
system "scp upload.tar $server:$dir";
}
}