scp +find


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users scp +find
# 15  
Old 11-14-2006
Solution

I found the solution using some perl modules. I attach the script:

#!/usr/local/bin/perl -w
use strict;
use Expect;
use File::Remote;

####################################################
# Could put a loop here with different host names so you can ssh to multiple servers...
####################################################
my $hostname = "fwtest";
my $user = "admin";

my $ssh = Expect->spawn("ssh -l $user $hostname"); #or return "Couldn't spawn ssh connection, ".$ssh->exp_error()."\n";

unless ($ssh->expect(30,-re,'#')) {
return "Never got the prompt on $hostname during login,
".$ssh->exp_error()."\n";
}
$ssh->clear_accum();

####################################################
# Verify version of firewall checkpoint (remote test command)
####################################################

my $cmd = "fw ver";
print $ssh "$cmd\r";

####################################################
# Enter in expert mode
####################################################
#print "\n", $sep, "Enter in expert mode.\n", $sep;
$cmd = "expert";
print $ssh "$cmd\r";
unless ($ssh->expect(30,-re,'#')) {
return "Never got the prompt on $hostname during login,
".$ssh->exp_error()."\n";
}
$ssh->clear_accum();
my $psw_exp = "didata123";
print $ssh "$psw_exp\r";

####################################################
# Change directory (where there are the log files)
####################################################

$cmd = "cd /opt/CPsuite-R60/fw1/log";
print $ssh "$cmd\r";
####################################################
# Find the right files (older than 15 days)
####################################################

$cmd = "cp `find *.log -mtime +15` log_backup";
unless ($ssh->expect(30,-re,'#')) {
return "Never got the prompt on $hostname during login,
".$ssh->exp_error()."\n";
}
$ssh->clear_accum();
print $ssh "$cmd\r";

# Now we look for a prompt, having (we hope) successfully logged in.
unless ($ssh->expect(30,-re,'#')) {
return "Never got ssh prompt after sending command $cmd
".$ssh->exp_error()."\n";
}
####################################################
# Use secure connection methods to retrive logswitch files
####################################################

my $secure = new File::Remote (rsh => "/usr/local/bin/ssh",
rcp => "/usr/local/bin/scp");
$secure->copy("fwtest:/opt/CPsuite-R60/fw1/log/log_backup/*.log", "/export/home/x2693/project/test/log_backup");

print "\n";


P.S. It's only the first version... It could be improved!
Smilie Smilie Smilie

Thanks a lot to Blowtorch, Sowser, Corona688, Just Ice for their helps.
See you!!!!!!!!!!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh find and scp

Hello All, I have a requirement to copy few files from remote server to local, and below are the sequence ssh to the remote host finding the files with the specific condition once found scp to the local server path for (( i=0; i<${tLen}; i++ )) do ssh... (1 Reply)
Discussion started by: nextStep
1 Replies

2. Shell Programming and Scripting

SCP

Hi All, Please help on the below command scp -r 'directory name'inrvgo@IP:/export/home/muthu/prod_12-09-2010 I am trying to copy a directory from one server to another server using the above command but its displaing the error (missing destination file) but the diectory was there in the... (1 Reply)
Discussion started by: thelakbe
1 Replies

3. Red Hat

scp with su

Hi Friends, I am trying to copy some files over the network in between my linux servers. I am using scp command for this. by default direct ssh root login is disabled on all of my linux servers. Normaly we used to login as a normal user and the su to th root user. unfortunately root user is... (1 Reply)
Discussion started by: arumon
1 Replies

4. Shell Programming and Scripting

find -exec scp

Hello, I'm facing a problem with a command that works on Linux but not on Unix (Solaris 10). I want to find files and scp then to another server. This command is: find /path -type f -exec scp {} root@node000C76211737:{} \; All the files are found correctly but it looks like the last... (7 Replies)
Discussion started by: Tex-Twil
7 Replies

5. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

6. Shell Programming and Scripting

Is this possible with SCP?

I normally download a directory recursively using: scp -r <name>@host:<path> . This has worked fine. As everyone knows this will download all of the directory named in <path> and all of the sub directories. I would like to know if it is possible to not download a particular file if it... (5 Replies)
Discussion started by: cpabrego
5 Replies

7. Shell Programming and Scripting

What is scp-ed over?

Hi all, i have a directory in server A. the directory path is /home/kevin. I need to scp the directory to another server B. i would like to ask, when i do a scp of the /home/kevin , i can expect all the files from A to go B. However, how about the hidden files? for example the ssh keys in the... (4 Replies)
Discussion started by: new2ss
4 Replies

8. UNIX for Advanced & Expert Users

Scp

I am trying to transfer a 10g files using scp, but I am getting timeout errors is there anywhere that I can modify a config file or something to increase the time. (4 Replies)
Discussion started by: rbizzell
4 Replies

9. UNIX for Dummies Questions & Answers

scp

How do i use scp to copy a file from my home directory on a server I am logged into, to the computer I am using? I thought it would be something like: scp filename mycomp.company.org Thanks. (2 Replies)
Discussion started by: ignus7
2 Replies
Login or Register to Ask a Question