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. |
and what is in /opt/scripts/dkremov.log?
|
I am sorry it si the script i posted:
And here is the script: date cd /opt/WebSphere/AppServer rm dklog.log |
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)? |
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 |
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 |
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 |
But does this execute from your own user's crontab?
Code:
*/5 * * * * date >> $HOME/cron.log |
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 |
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 Code:
*/5 * * * * /opt/scripts/dklogremv.sh > $HOME/cron.log 2> $HOME/cron.err |
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! |
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. |