LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problems excuting a script through cron (https://www.linuxquestions.org/questions/programming-9/problems-excuting-a-script-through-cron-4175447855/)

ljmace1953 01-30-2013 10:03 AM

Problems excuting a script through cron
 
This is driving me a bit crazy(er). I haven't had to work with Linux in a while and I know I am missing something but cannot put my finger on it. I have google it to death and have just given up.

I know it is somewhere in the permissions but can not for the life of me figure it out so I have come for help.

I need to delete a file while th DB is down. The DB is down but when I come in the file is still there.
I have even tried a test file (one that I have vi'ed and I own) and still can not get it work through cron. I can delete it by executing it(./)

I will not bore you with my test file. Here is a listing of the prod file:
-rw-r--r-- 1 root root 17383315 2013-01-30 09:51 dklog.log

When I created the script I created it as root here is the listing of it:
-rwxrwxrwx 1 root root 46 2013-01-28 07:21 dklogremv.sh

And here is the script:
date
cd /opt/WebSphere/AppServer
rm dklog.log

Here is the crontab listing:
59 1 * 1-12 0 /opt/scripts/dklogremv.sh > /opt/scripts/dkremov.log

The file does exist in this directory (/opt/WebSphere/AppServer)
What am I missing????
Any help is deeply appreciated.

pan64 01-30-2013 10:08 AM

and what is in /opt/scripts/dkremov.log?

ljmace1953 01-30-2013 10:21 AM

I am sorry it si the script i posted:
And here is the script:
date
cd /opt/WebSphere/AppServer
rm dklog.log

colucix 01-30-2013 10:27 AM

What pan64 was asking is to show the content of the log file /opt/scripts/dkremov.log, since you used redirection in the crontab entry. Also check the mail of the crontab owner, where standard error (not redirected to a file) should have been sent (if any).

An aside note: what is the purpose of the 1-12 interval in the month field? Doesn't it equal to * (month not restricted)?

ljmace1953 01-30-2013 10:45 AM

There is nothing in it, that is another mystery. the first time it executed there was nothing so I put the date command in it to see if it was executing.
Yes 1-12 is the same as *, truthfully I don't know why I did it

colucix 01-30-2013 11:02 AM

Ok. A silly question: have you tried a simple crontab entry to see if it is a generic problem like "the system doesn't let my user run cron jobs" or "the cron daemon is down"? Example:
Code:

*/5 * * * * date >> $HOME/cron.log
This should run every 5 minutes, that is at 0,5,10,15.... minutes of every hour.

ljmace1953 01-30-2013 11:06 AM

Part of the problem is this is roots' crontab and I have at least 10 other simular functions.
So I set up a cron for my own user id with a test file and I can not get that one to delte either using cron

colucix 01-30-2013 11:11 AM

But does this execute from your own user's crontab?
Code:

*/5 * * * * date >> $HOME/cron.log
I mean apart the permissions problems of the script in /opt (if any).

ljmace1953 01-30-2013 01:07 PM

Yep works:

cron.log Documents public_html test1
cat cron.log
Wed Jan 30 13:55:01 EST 2013
Wed Jan 30 14:00:01 EST 2013
Wed Jan 30 14:05:01 EST 2013

colucix 01-30-2013 02:26 PM

Ok, the user's crontab is working. Now about the permissions: the script should be executable by the user (but you can always change the ownership of the script). The file instead cannot by removed by a normal user, not only because permissions prevent it:
Code:

-rw-r--r-- 1 root root 17383315 2013-01-30 09:51 dklog.log
but also because the directory where the script is placed should belong to (or have permissions for) the crontab owner. And maybe for this reason the log file placed in the same directory has not been updated by the date command in your script. What about trying something like this, just for testing purposes?
Code:

*/5 * * * * /opt/scripts/dklogremv.sh > $HOME/cron.log 2> $HOME/cron.err

ljmace1953 01-31-2013 07:29 AM

I had to use the script for my test file and the cron statement worked. I don't know why though.
The file i need to remove is a DB2 log that is in use and I will not have a chance to remove until Monday morning.
BUT I am more than a little confused why this worked all the sudden!
I will not update this until Monday when i get in. I will add the correct cron job back into roots' crontab.
Thank you very much!

ljmace1953 02-04-2013 09:28 AM

I want to thank all of you for your help.
I am a bit embarssed to say that after thes testing examples given by colucix i really began to look at the script.
Well long story short I was pointed at the wrong library.
Again, thank you for all your help


All times are GMT -5. The time now is 06:39 PM.