Cron Job

Hi everyone…I am a bit of a newbie when it comes to Linux (REHL) and
I am trying to add this RT command as a cron job via crontab.

I am logged in as root and when I run this manually:

/opt/rt3/bin/rt list -i “Status = ‘in-review’ AND Resolved < ‘2 days
ago’” | /opt/rt3/bin/rt edit - set status=resolved

it works great.

When I add it to crontab it doesn’t run and here is result of…

crontab -l
01 00 * * * /opt/rt3/bin/rt list -i “Status = ‘in-review’ AND Resolved
< ‘2 days ago’” | /opt/rt3/bin/rt edit - set status=resolved

/var/log/cron

Jun 5 10:01:01 dcrt crond[8839]: (root) CMD (/opt/rt3/bin/rt list -i
"Status = ‘in-review’ AND Resolved < ‘2 days ago’" | /opt/rt3/bin/rt
edit - set status = ‘resolved’^M)

Everything appears correct…though I am not sure what the ^M indicates
at the end of the cron command in the log file.

any thoughts?

-Stark

Hi everyone…I am a bit of a newbie when it comes to Linux (REHL)
and I am trying to add this RT command as a cron job via crontab.

I am logged in as root and when I run this manually:

/opt/rt3/bin/rt list -i “Status = ‘in-review’ AND Resolved < ‘2 days
ago’” | /opt/rt3/bin/rt edit - set status=resolved

it works great.

When I add it to crontab it doesn’t run and here is result of…

crontab -l
01 00 * * * /opt/rt3/bin/rt list -i “Status = ‘in-review’ AND
Resolved < ‘2 days ago’” | /opt/rt3/bin/rt edit - set status=resolved

/var/log/cron

Jun 5 10:01:01 dcrt crond[8839]: (root) CMD (/opt/rt3/bin/rt list -i
“Status = ‘in-review’ AND Resolved < ‘2 days ago’” | /opt/rt3/bin/rt
edit - set status = ‘resolved’^M)

Everything appears correct…though I am not sure what the ^M
indicates at the end of the cron command in the log file.

Hi Jeff,

The ^M just means that you copied the command line from a MS Windows
application into your terminal application - it’s a Windows return
character.

Do a ‘crontab -e’ go to the end of the line and delete the any trailing
spaces - that should remove it from your logs and maybe fix your
problem.

IF it doesn’t, put the command into a shell script and run that via cron

  • maybe cron doesn’t have a nice default shell or something.

Ken.

This email has passed through an IE Internet MailWall gateway
and has been screened for known viruses, potential viruses and
malicious code.

IE Internet.com MailWall (http://ieinternet.com/mailwall/)

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.)

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

  2. 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 ()
{
(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 = testcopesan@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
bbaker@copesan.commailto:cstephan@copesan.com
www.copesan.comhttp://www.copesan.com/
“Servicing North America with Local Care”