Looking for a better way!

This is what I have done so far.  I created the following Perl script which 
connects to a foreign data to determine if there are any available agents login 
to the phone system.
If there are agents to send messages to then run getmail to retrieve the 
messages.  It also makes sure the Getmail process is not already running.

Why do I want something better

1.       I get the following error when this runs. But messages appear to be 
delivered.

a.  Delivery error (command rt-mailgate 9285 wrote to stderr: cannot chdir to 
/root from /tmp/VurewGNWhm: Permission denied, aborting. at 
/usr/lib/perl5/5.16.2/File/Temp.pm line 902.)

b.    msg 575/594 (85001 bytes), delivery error (command rt-mailgate 9285 wrote 
to stderr: cannot chdir to /root from /tmp/VurewGNWhm: Permission denied, 
aborting. at /usr/lib/perl5/5.16.2/File/Temp.pm line 902.)

2.  I continue to get all kinds of directories left behind in the /tmp 
directory.

3.  I am a newbe and know there has to be a better way.

Script being ran by cron as "root"

#!/usr/bin/perl -w
use DBI;
use DateTime;

my $host = '192.168.254.10';
my $port = '4308';
my $database = '';
my $user = '';
my $password = '';
my $command2 = " ";
my $currentID = $$;
my $dt = DateTime->now;

open(FILE, "ps aux|");
while (<FILE>)
{
(my $uid,my $pid,my $cpu,my $mem,my $vsz,my $rss,my $tty,my $stat,my $start,my 
$time,my $command,my $command1,my $command2) = split;

$command = $command // "Unknown";
$command = $command1 // "Unknown";
$command = $command2 // "Unknown";

my $result = index($command, "/usr/bin/getmail");
if ($pid ne $currentID)
{
   if ($result > -1)
   {
     print "$dt Scrip already running $command $pid $currentID $result\n";
     exit;
   }
}
}
my $dsn = "DBI:mysql:database=$database;host=$host;port=$port ";
my $dbh = DBI->connect($dsn,  $user, $password);

my $sql = 'SELECT tabaddress.EmailAddress FROM shoreware.ports as Ports ';
$sql = $sql . 'inner join (shoreware.usercurrentswitch as UCS) on (Ports.PortID 
= UCS.HomePortID) ' ;
$sql = $sql . 'inner join (shoreware.users as Users) on (Ports.CurrentDN = 
Users.UserDN) ';
$sql = $sql . 'inner join (shoreware.workgroupagents as Agents) on 
(Users.UserDN = Agents.UserDN) ';
$sql = $sql . 'inner join (shoreware.Tabaddresses as tabaddress) on 
(Users.AddressID = tabaddress.AddressID) ';
$sql = $sql . 'Where (Ports.JackNumber not like \'%norr%\' or Ports.JackNumber 
is null and Agents.agentstateID<>0) ';
$sql = $sql . 'order by Agents.UserDN ';

my $sth = $dbh->prepare($sql);
$sth->execute;
my $rows = $sth->rows;
if ($rows > 0)
{
  system("cd /tmp");
  system("getmail");
  print "$dt Number of rows $rows\n";
}

Getmail configuration

[retriever]

#type = SimpleIMAPSSLRetriever

#server = imap.gmail.com

#port = 993

#username = testcope...@gmail.com

#password =

#mailboxes = ('BBaker',)



type = SimpleIMAPRetriever

server = 192.168.250.61

port = 143

username = clientservice@copesan.local

password =

mailboxes = ('To_Request_Tracker',)



[destination]

type = MDA_external

path = /usr/bin/rt-mailgate

user = rtuser

group = rtgroup

arguments = ("--url", "http://localhost/rt";, "--queue", "x CSR", "--action", 
"correspond",)



[options]

read_all = false

delete = false

received = false

delivered_to = false

message_log = /var/log/request-tracker/mvmail.log

Thanks in advance for all the help.

Bryon Baker
Network Operations Manager
Copesan - Specialists in Pest Solutions
800-267-3726  *  262-783-6261 ext. 2296
bba...@copesan.com<mailto:cstep...@copesan.com>
www.copesan.com<http://www.copesan.com/>
"Servicing North America with Local Care"

Reply via email to