LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2014, 06:53 AM   #1
clstanton
LQ Newbie
 
Registered: May 2008
Posts: 27

Rep: Reputation: 0
scp file and include directory info


Good morning. I have an issue with core files. They are showing up in different directories. I want to move them to another location however they are all named "core" so I need to attach the directory tree information so they can be identified later as to where they came from.

So far I have not been able to find a similar problem or solution. I did see an example of someone using the tree command however I did not understand what they were doing.

so I want to scp the core files to a single directory on a different box

/dir1/dir2/dir3/core
/dir1/dir2/dir4/core
/dir1/dir5/dir6/core

Thanks in advance if somebody can help
 
Old 10-08-2014, 07:33 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Here's some code (untested) that makes a new ssh call for every core file it copies (inconvenient if prompted for password)
You probably want to remove the original after the transfer.

Code:
#! /usr/bin/perl -w
    eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
        if 0; #$running_under_some_shell

use strict;
use File::Find ();

# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;
sub transfer_to_otherhost ();

my @rwx = qw(--- --x -w- -wx r-- r-x rw- rwx);
my @moname = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

my (%uid, %user);
while (my ($name, $pw, $uid) = getpwent) {
    $user{$uid} = $name unless exists $user{$uid};
}

my (%gid, %group);
while (my ($name, $pw, $gid) = getgrent) {
    $group{$gid} = $name unless exists $group{$gid};
}

# Traverse desired filesystems - just named two here
File::Find::find({wanted => \&wanted}, '/home', '/');
exit;

sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    !($File::Find::prune |= ($dev != $File::Find::topdev)) &&
    -f _ &&
    /^core\z/s &&
    transfer_to_otherhost;
}


sub sizemm {
    my $rdev = shift;
    sprintf("%3d, %3d", ($rdev >> 8) & 0xff, $rdev & 0xff);
}

sub transfer_to_otherhost () {
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
    my $pname = $name;

    $_=$name;
    s/\//./g;
    my $newname = ".".time();

    open(STDIN, "<$pname") or return 2;
    # user host and directory name will want changing
    system("/usr/bin/ssh", "coreuser\@corehost", "cat > coredirectory/" . $newname);

    1;
}
 
Old 10-08-2014, 07:42 AM   #3
clstanton
LQ Newbie
 
Registered: May 2008
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks. My hope is to run as a cron job so I would need and that does prompt for a password.
 
Old 10-08-2014, 07:43 AM   #4
clstanton
LQ Newbie
 
Registered: May 2008
Posts: 27

Original Poster
Rep: Reputation: 0
Sorry I was distracted. What I wanted to say is I need something that will not need human interaction. This has given me some ideas to persue.
 
Old 10-08-2014, 07:47 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,350

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
I would try rsync
 
Old 10-08-2014, 08:29 AM   #6
clstanton
LQ Newbie
 
Registered: May 2008
Posts: 27

Original Poster
Rep: Reputation: 0
Thank you. I was not aware of the rsync command. I will study up on it and see if I can apply it. On first look though it seems that because the files have the same name they will be over written or modified anyway.
 
  


Reply

Tags
scp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
SCP: No such file or directory...but its there!? Baix Linux - Newbie 20 07-28-2012 02:42 PM
QT #include <QGLWidget> no such file or directory problem ZebraIzToronto Programming 2 05-30-2011 11:45 AM
PHP include file directory/paths DMeerholz Linux - Software 1 07-02-2007 10:21 AM
/usr/include/rpm: No such file or directory powah Red Hat 3 10-31-2006 10:27 AM
#include <task.h> : No such file or directory Eileen Programming 1 04-20-2006 03:26 AM


All times are GMT -5. The time now is 12:28 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration