Re: CRON & CRONTAB

 
SOLVED
Go to solution
Me_9
Occasional Advisor

CRON & CRONTAB

Recently starting using a script which I would like automated.

Opened /etc/crontab and added the following:

00,15,30,45 * * * * root /usr/xyz/script.pl

Now when cron begins it starts the perl script but it fails to open the associated files (*.cfg, *.tmp, etc). Returns an error "no such file".

In the directory xyz are the script, configuration, and template files all necessary to run the script.

I have added /usr/xyz to the path statement in crontab and in ld.so.conf. Yet the error remains.

Does someone know how to delimit the directory so that cron can execute the script.
4 REPLIES 4
Tom Dyll
Occasional Contributor

Re: CRON & CRONTAB

I had a similar problem trying to create a shell script for dyndns. The solution was to add a line that changed to the directory that contained those files and then execute the script.

The only diff is I use crontab with the following options and keep my cron jobs in the apropriate directories.

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

#! /bin/bash
#
# change into directory
cd /opt/dyndns
# execute script
ipcheck.py -l -v username password dnsaddress
Alan Deger
Trusted Contributor

Re: CRON & CRONTAB

You could probably learn a lot about the environment your cron account is inheriting by
kicking off a job "set > /cronenv.txt" and catting that after it runs.

-ard
Me_9
Occasional Advisor

Re: CRON & CRONTAB

Thanks, to both of you.

The solution developed as such from your input.

1) modify etc/crontab to read "00,15,30,45 * * * * root /usr/xyz/runscript.pl

2) runscript.pl contained the following:

# !/bin/bash
cd /usr/xyz
cd ./script.pl

Now all works correctly.

Thanks again!!
Eric Ladner
Trusted Contributor
Solution

Re: CRON & CRONTAB


The problem is that the command lines in cron are executed directly with a shell command.

The way to get around this (and a cleaner solution in your case) is to change the original cron entry to this:

00,15,30,45 * * * * root /usr/bin/perl /usr/xyz/script.pl

(provided your perl interpreter lives at /usr/bin/perl)