LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   scp file and include directory info (https://www.linuxquestions.org/questions/linux-newbie-8/scp-file-and-include-directory-info-4175521429/)

clstanton 10-08-2014 06:53 AM

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

linosaurusroot 10-08-2014 07:33 AM

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;
}


clstanton 10-08-2014 07:42 AM

Thanks. My hope is to run as a cron job so I would need and that does prompt for a password.

clstanton 10-08-2014 07:43 AM

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.

pan64 10-08-2014 07:47 AM

I would try rsync

clstanton 10-08-2014 08:29 AM

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.


All times are GMT -5. The time now is 06:15 PM.