From 186064c57aa8a8256f74ac1a226f8e760ec3d264 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 1 Oct 2005 16:13:26 +0000 Subject: [PATCH] script to tar up process related /proc files --- exp/tar_proc.pl | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 exp/tar_proc.pl diff --git a/exp/tar_proc.pl b/exp/tar_proc.pl new file mode 100644 index 00000000..f5830fc1 --- /dev/null +++ b/exp/tar_proc.pl @@ -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 ; + 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"; + +