[Sussex] workaround script
John Crowhurst
fyremoon at fyremoon.net
Sun Oct 3 22:30:55 UTC 2004
Thomas Adam wrote:
> system() in perl will, if I follow what you're asking.
Thanks, that works a charm. I just thought that as `` didn't work, system
wouldn't either.
Here is my perl version of that script:
#!/usr/bin/perl
# Read from command line
foreach $filename (@ARGV) {
# Create backup file
$time=time;
$backup="/tmp/$time";
open(IN, "< $filename") or die "can't open $filename: $!";
open(OUT, "> $backup") or die "can't open $backup: $!";
@IN=<IN>;
foreach $in (@IN) {
print OUT "$in";
}
close(OUT);
close(IN);
# pass the file to the editor
$result=system("/usr/bin/joe $filename");
# create a unified diff of the result
$result=system("diff -u $backup $filename >/tmp/changes");
# Check to see if the changes file is empty
if (-z "/tmp/changes") {
print "Zero Changes!\n";
} else {
# Mail the diff to the user who is using the editor
open (MAIL, "|/usr/lib/sendmail -t");
open (CHANGES, "</tmp/changes");
@CHANGES=<CHANGES>;
close(CHANGES);
$user=$ENV{'USER'};
$subject="joe: $filename changes";
print MAIL "To: $user\n";
print MAIL "From: $user\n";
print MAIL "Reply-To: $user\n";
print MAIL "Subject: $subject\n\n";
print MAIL @CHANGES;
close(MAIL);
}
# dispose of unnecessary files
unlink($backup);
unlink("/tmp/changes");
}
More information about the Sussex
mailing list