Иван Бессарабов skrev 02. juli 2009 08:42: > I've had a task - every morning I needed to send list of task to the owners > of that tikets. > > I've written the small script in perl language. The script is avaliable in > my blog, but the blog is in russian language > http://blog.bessarabov.ru/2008/07/23/send-active-trac-tickets-to-mail/ > > I've placed that script into the crontab. > > Feel free to contact me on any questions about this script. >
I made a minor change, and translated the comments to English (I hope, I don't speak russian ;-). Just in case it's usefull for someone on this list. I tested the script briefly, and it appears to work correctly. Best regards, -- .---. Eirik Schwenke <[email protected]> ( NSD ) Harald Hårfagresgate 29 Rom 150 '---' N-5007 Bergen tlf: (555) 889 13 GPG-key at pgp.mit.edu Id 0x8AA3392C
#! /usr/bin/perl use strict; use warnings; use DBI; # Cron script for sending regular reminders to ticket owner. # # Call from Cron, or Windows Scheduler. # # Original author: Ðван ÐеÑÑаÑабов # Upstream version: http://blog.bessarabov.ru/2008/07/23/send-active-trac-tickets-to-mail/ # # Simplisting translation to English and minor modifications by # Eirik Schwenke <[email protected]> . Any errors in this version is not the fault of # the original author. # # Help with transalation provided by http://babelfish.yahoo.com/ ### ### Start - configuration settings # Path to trac install: my $trac = "/var/trac/test"; # Ticket owner my $owner = "some_user"; # Email address where reminder is sent my $email = "[email protected]"; ### End - configuration settings ### # Attempt to connect to trac database: my $file = $trac . "/db/trac.db"; my $dbh = DBI->connect("dbi:SQLite:dbname=$file","","", { RaiseError => 1, PrintError => 0 }) or die "Failed to connect to SQLite filesystem digest cache database at $file: " . DBI->errstr; $dbh->{unicode} = 1; # The query to be executed. This searches for all active tickets. my $sth = $dbh->prepare(" SELECT id, summary FROM ticket WHERE status IN ('new', 'assigned', 'reopened') AND owner = '$owner' ORDER BY id"); $sth->execute(); # Slurp all result into $content variable. my $content; while (my $result = $sth->fetchrow_hashref) { $content .= "#" . $result->{id} . " - ". $result->{summary} . "\n"; } # If the there is at least one ticket... if ($content) { # ... then we construct the message to be sent to owner: $content = "All active tickets for user $owner\n\n" . $content; # ... and attemt to send the email open(MAIL, "|mail $email -s 'All active tickets for user $owner'") or die "Cannot open mail: $!"; binmode MAIL, ":utf8"; print MAIL $content; close(MAIL); } $sth->finish;
signature.asc
Description: OpenPGP digital signature
