Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

jdavidb
  (email not shown publicly)
http://voiceofjohn.blogspot.com/

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Friday November 01, 2002
08:01 AM

More code

[ #8722 ]

Finally decided to codify my semi-daily debian update procedure. Instead of a shell script, I decided to write a Perl program, and instead of just doing a bunch of system ""'s I decided to turn on taint-checking and use the multi-arg form. Also played with getpw* stuff, Time::Piece->strftime, and redirecting STDOUT, all of which are features I don't mess with much.

#!/usr/local/bin/perl5.8.0 -T

use warnings;
use strict;

use Time::Piece;

my $HOME = get_users_home();
my($cachefile, $packagefile) = ("$HOME/apt-cache", "$HOME/packages");
my $date = localtime->strftime("%Y%m%d");

$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";

system qw(apt-get update);
system qw(apt-get dist-upgrade);
system qw(apt-get autoclean);
open my $fh, ">$cachefile" or die "Can't open $cachefile: $!";
open STDOUT, ">&" . fileno($fh) or die "Can't redirect STDOUT: $!";
system qw(apt-cache dumpavail);
close $fh or warn "Couldn't close $cachefile: $!";
open $fh, $cachefile or die "Can't open $cachefile: $!";
open my $pfh, ">$packagefile" or die "Can't open $packagefile: $!";
while (defined(my $line = <$fh>))
{
  next unless $line =~ m/^Package: /;
  print $pfh $line;
}
link $packagefile, "$packagefile.$date" or warn "Couldn't link $packagefile to $packagefile.$date";

sub get_users_home
{
  return (getpwuid($<))[7];
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.