script to tar up process related /proc files

This commit is contained in:
Doug MacEachern 2005-10-01 16:13:26 +00:00
parent f2b304ea3c
commit 186064c57a
1 changed files with 42 additions and 0 deletions

42
exp/tar_proc.pl Normal file
View File

@ -0,0 +1,42 @@
#!perl
#create a .tar.gz of /proc/*/@proc_files
use strict;
my(@proc_files) = qw(cmdline stat statm status);
my $cpname = "copy-proc";
my $tmp = $ENV{TMPDIR} || "/tmp";
my $tmpdir = "$tmp/$cpname";
unless (-e $tmpdir) {
mkdir $tmpdir or die "mkdir $tmpdir: $!";
print "created $tmpdir\n";
}
opendir DH, "/proc" or die;
chdir "/proc";
while (my $pid = readdir DH) {
next unless $pid =~ /^\d+$/;
for my $name (@proc_files) {
unless (-e "$tmpdir/$pid") {
mkdir "$tmpdir/$pid";
}
local *SRC, *TARG;
my $file = "$pid/$name";
open SRC, $file or next;
open TARG, ">$tmpdir/$file" or die "open $tmpdir/$file: $!";
print TARG <SRC>;
close TARG;
close SRC;
}
}
chdir $tmp or die "chdir $tmp: $!";
system "tar -cf $cpname.tar $cpname";
system "gzip -f $cpname.tar";
print "files saved to $tmp/$cpname.tar.gz\n";
print "to cleanup, run: rm -rf $tmp/$cpname\n";