1834431 Members
2672 Online
110067 Solutions
New Discussion

cron error?

 
Richard A. Preugschat
Occasional Advisor

cron error?

I think am missing something here...

I'm trying to add basic command line 'test' to a cronjob entry, but I keep getting a rc=1 in the cron log.

From the command line:

$ [[ -d /home/rap ]] && print here || print "not here" ;echo $?
here
0

$ [[ ! -d /home/rap ]] && print here || print "not here" ;echo $?
not here
0

now added this to cron for test purposes....

* * * * * [[ ! -d /home/rap ]] && print here || print "not here"

cron log result....
CMD: [[ ! -d /kgegt/kgegate ]] && print here || print "not here"
> rap 3941 c Thu Dec 12 13:01:00 GMT 2002
< rap 3941 c Thu Dec 12 13:01:00 GMT 2002 rc=1

I know about the ">/dev/null 2>&1" should be put after the print commands, thats not the issue.

The bottom line is, I want to check for a directory on the commandline,
and if its there, run a script and if its not, exit cleanly without a cron entry error.

Any advice would be much appreicated, thanks.....
Richard



6 REPLIES 6
John Poff
Honored Contributor

Re: cron error?

Hi Richard,

It might be possible to do it the way you are trying, but I'd be inclined to put the test inside of the script, and have the script test for the directory and exit if it isn't there.

That way, your crontab is much cleaner, and you can modify and add tests to the script as needed without having to mess with cron.

JP
John Palmer
Honored Contributor

Re: cron error?

Hi,

I too would recommend a wrapper script for this. However, I've tested your cron entry on both 10.20 and 11.00 and it works fine.

My 11.00 test system does have the latest cron/at patch applied (PHCO_27141), suggest you check your system.

Regards,
John
Tom Jackson
Valued Contributor

Re: cron error?

Hi Richard:

I would have an entry in cron that just does a call to a script.

Here a script that might work for you:

#!/sbin/sh
if ( test -f /home/rap ) then
echo "found it!"
else
echo "did not find it!"
fi

Tom
Paula J Frazer-Campbell
Honored Contributor

Re: cron error?

Richard

As said it if far neater and more controlable to put this in a script and then call it from cron.

Ensure that within your script that you define all environmental variables that your script may need.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Robin Wakefield
Honored Contributor

Re: cron error?

Hi Richard,

You could put a "sleep 10;" in front of your command. If the rc=1 message still occurs straight away, then it's likely to be your environment, not the commands themselves.

Rgds, Robin
Richard A. Preugschat
Occasional Advisor

Re: cron error?

Hello everybody,

Thanks for the info, the final fix I found, was to check for the file explicitly, i.e.

[[ -f /home/rap/do-it.sh ]] && /home/rap/do-it.sh || :

This checks for the file, if there, exec it, if not do nothing

Thanks for all your useful pointers....

Richard

P.S. Its the first time I've used this system and its great to get really quick responses, which help me fix my problem.